]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New ITS code for new structure and simulations.
authornilsen <nilsen@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 12 Jun 2000 23:40:07 +0000 (23:40 +0000)
committernilsen <nilsen@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 12 Jun 2000 23:40:07 +0000 (23:40 +0000)
57 files changed:
ITS/AliITSClusterFinder.cxx [new file with mode: 0644]
ITS/AliITSClusterFinder.h [new file with mode: 0644]
ITS/AliITSClusterFinderSDD.cxx [new file with mode: 0644]
ITS/AliITSClusterFinderSDD.h [new file with mode: 0644]
ITS/AliITSClusterFinderSPD.cxx [new file with mode: 0644]
ITS/AliITSClusterFinderSPD.h [new file with mode: 0644]
ITS/AliITSClusterFinderSSD.cxx [new file with mode: 0644]
ITS/AliITSClusterFinderSSD.h [new file with mode: 0644]
ITS/AliITSDetType.cxx [new file with mode: 0644]
ITS/AliITSDetType.h [new file with mode: 0644]
ITS/AliITSHuffman.cxx [new file with mode: 0644]
ITS/AliITSHuffman.h [new file with mode: 0644]
ITS/AliITSMap.cxx [new file with mode: 0644]
ITS/AliITSMap.h [new file with mode: 0644]
ITS/AliITSRawCluster.cxx [new file with mode: 0644]
ITS/AliITSRawCluster.h [new file with mode: 0644]
ITS/AliITSRawData.cxx [new file with mode: 0644]
ITS/AliITSRawData.h [new file with mode: 0644]
ITS/AliITSRecPoint.h [new file with mode: 0644]
ITS/AliITSclusterSSD.cxx [new file with mode: 0644]
ITS/AliITSclusterSSD.h [new file with mode: 0644]
ITS/AliITSdcsSSD.cxx [new file with mode: 0644]
ITS/AliITSdcsSSD.h [new file with mode: 0644]
ITS/AliITSdictSSD.cxx [new file with mode: 0644]
ITS/AliITSdictSSD.h [new file with mode: 0644]
ITS/AliITSetfSDD.cxx [new file with mode: 0644]
ITS/AliITSetfSDD.h [new file with mode: 0644]
ITS/AliITSpackageSSD.cxx [new file with mode: 0644]
ITS/AliITSpackageSSD.h [new file with mode: 0644]
ITS/AliITSresponse.h [new file with mode: 0644]
ITS/AliITSresponseSDD.cxx [new file with mode: 0644]
ITS/AliITSresponseSDD.h [new file with mode: 0644]
ITS/AliITSresponseSPD.cxx [new file with mode: 0644]
ITS/AliITSresponseSPD.h [new file with mode: 0644]
ITS/AliITSresponseSSD.cxx [new file with mode: 0644]
ITS/AliITSresponseSSD.h [new file with mode: 0644]
ITS/AliITSsegmentation.h [new file with mode: 0644]
ITS/AliITSsegmentationSDD.cxx [new file with mode: 0644]
ITS/AliITSsegmentationSDD.h [new file with mode: 0644]
ITS/AliITSsegmentationSPD.cxx [new file with mode: 0644]
ITS/AliITSsegmentationSPD.h [new file with mode: 0644]
ITS/AliITSsegmentationSSD.cxx [new file with mode: 0644]
ITS/AliITSsegmentationSSD.h [new file with mode: 0644]
ITS/AliITSsimulation.cxx [new file with mode: 0644]
ITS/AliITSsimulation.h [new file with mode: 0644]
ITS/AliITSsimulationFastPoints.cxx [new file with mode: 0644]
ITS/AliITSsimulationFastPoints.h [new file with mode: 0644]
ITS/AliITSsimulationSDD.cxx [new file with mode: 0644]
ITS/AliITSsimulationSDD.h [new file with mode: 0644]
ITS/AliITSsimulationSPD.cxx [new file with mode: 0644]
ITS/AliITSsimulationSPD.h [new file with mode: 0644]
ITS/AliITSsimulationSSD.cxx [new file with mode: 0644]
ITS/AliITSsimulationSSD.h [new file with mode: 0644]
ITS/AliITSstatistics.cxx [new file with mode: 0644]
ITS/AliITSstatistics.h [new file with mode: 0644]
ITS/AliITSstatistics2.cxx [new file with mode: 0644]
ITS/AliITSstatistics2.h [new file with mode: 0644]

diff --git a/ITS/AliITSClusterFinder.cxx b/ITS/AliITSClusterFinder.cxx
new file mode 100644 (file)
index 0000000..c925bc4
--- /dev/null
@@ -0,0 +1,124 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+#include "AliITSClusterFinder.h"
+#include "TTree.h"
+#include "AliRun.h"
+#include <TCanvas.h>
+#include <TH1.h>
+#include <TPad.h>
+#include <TGraph.h> 
+#include <TPostScript.h> 
+#include <TMinuit.h> 
+
+class AliITSRecPointNew;
+
+//----------------------------------------------------------
+
+//----------------------------------------------------------
+
+ClassImp(AliITSClusterFinder)
+
+AliITSClusterFinder::AliITSClusterFinder
+(AliITSsegmentation *seg, AliITSresponse *response, TClonesArray *digits)   
+{
+  // cluster finder
+    fSegmentation=seg;
+    fResponse=response;
+    fMap = 0;
+    
+    fDigits=digits;
+    fNdigits = fDigits->GetEntriesFast();
+
+    fNRawClusters=0;
+
+    SetNperMax();
+    SetClusterSize();
+    SetDeclusterFlag();
+
+    fNPeaks=-1;
+}
+
+//----------------------------------------------------------
+AliITSClusterFinder::AliITSClusterFinder()
+{
+  // constructor
+    fResponse=0;
+    
+    fDigits=0;
+    fNdigits = 0;
+
+    fNRawClusters=0;
+    fMap = 0;
+
+
+    SetNperMax();
+    SetClusterSize();
+    SetDeclusterFlag();
+
+    fNPeaks=-1;
+}
+//__________________________________________________________________________
+AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fDigits = source.fDigits;
+  this->fNdigits = source.fNdigits;
+  this->fResponse = source.fResponse;
+  this->fSegmentation = source.fSegmentation;
+  this->fNRawClusters = source.fNRawClusters;
+  this->fMap = source.fMap;
+  this->fNperMax = source.fNperMax;
+  this->fDeclusterFlag = source.fDeclusterFlag;
+  this->fClusterSize = source.fClusterSize;
+  this->fNPeaks = source.fNPeaks;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSClusterFinder& 
+  AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fDigits = source.fDigits;
+  this->fNdigits = source.fNdigits;
+  this->fResponse = source.fResponse;
+  this->fSegmentation = source.fSegmentation;
+  this->fNRawClusters = source.fNRawClusters;
+  this->fMap = source.fMap;
+  this->fNperMax = source.fNperMax;
+  this->fDeclusterFlag = source.fDeclusterFlag;
+  this->fClusterSize = source.fClusterSize;
+  this->fNPeaks = source.fNPeaks;
+  return *this;
+}
+
+//----------------------------------------------------------
+void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c)
+{
+  //
+  // Add a raw cluster copy to the list
+  //
+    AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
+    iTS->AddCluster(branch,c); 
+    fNRawClusters++;
+}
+
+
+
+
+
diff --git a/ITS/AliITSClusterFinder.h b/ITS/AliITSClusterFinder.h
new file mode 100644 (file)
index 0000000..509fcd8
--- /dev/null
@@ -0,0 +1,125 @@
+#ifndef ALIITSCLUSTERFINDER_H
+#define ALIITSCLUSTERFINDER_H
+
+
+////////////////////////////////////////////////
+//  ITS Cluster Finder Class                 //
+////////////////////////////////////////////////
+
+#include "AliITSMap.h"
+
+//---------------------------------------------------------------
+class AliITSClusterFinder :public TObject
+{
+public:
+  TClonesArray           *fDigits;      // digits
+  Int_t                   fNdigits;     // num of digits
+  
+  AliITSClusterFinder(AliITSsegmentation *seg, AliITSresponse *resp, TClonesArray *digits);
+  AliITSClusterFinder();
+  virtual ~AliITSClusterFinder(){
+    // destructor
+  }
+  AliITSClusterFinder(const AliITSClusterFinder &source); // copy constructor
+  AliITSClusterFinder& operator=(const AliITSClusterFinder &source); // assignment operator
+
+  virtual void SetResponse(AliITSresponse *response) {
+    // set response
+    fResponse=response;
+  }
+  virtual void SetSegmentation(AliITSsegmentation *segmentation) {
+    // set segmentation
+    fSegmentation=segmentation;
+  }
+  
+  virtual void SetDigits(TClonesArray *ITSdigits) {
+    // set digits
+    fDigits=ITSdigits;
+    fNdigits = fDigits->GetEntriesFast();
+  }
+  virtual Int_t   NDigits() {
+    // Get Number of Digits
+    return fNdigits;
+  }
+  
+  virtual void SetMap() {
+    // set map
+  }
+  AliITSMap   *Map()  {
+    // map
+    return fMap;
+  }
+  //
+  virtual void AddCluster(Int_t branch, AliITSRawCluster *c);
+  
+  virtual void FindRawClusters() {
+    // Search for raw clusters
+  }
+  virtual void FindCluster(Int_t i, Int_t j, AliITSRawCluster *c) {
+    // find cluster
+  }
+  
+  virtual void Decluster(AliITSRawCluster *cluster) {
+    // Decluster
+  }
+  virtual void SetNperMax(Int_t npermax=3) {
+    // Set max. Number of cells per local cluster
+    fNperMax = npermax;
+  }
+  virtual void SetDeclusterFlag(Int_t flag=1) {
+    // Decluster ?
+    fDeclusterFlag =flag;
+  }
+  virtual void SetClusterSize(Int_t clsize=3) {
+    // Set max. cluster size ; bigger clusters will be rejected
+    fClusterSize = clsize;
+  }
+  virtual void CalibrateCOG() {
+    // Self Calibration of COG 
+  }
+  virtual void CorrectCOG(){
+    // correct COG
+  }
+  
+  virtual Bool_t Centered(AliITSRawCluster *cluster) {
+    // cluster
+    return kTRUE;
+  }
+  virtual void   SplitByLocalMaxima(AliITSRawCluster *cluster) {
+    // split by local maxima
+  }
+  virtual void   FillCluster(AliITSRawCluster *cluster, Int_t) {
+    // fiil cluster
+  }
+  virtual void   FillCluster(AliITSRawCluster *cluster) {
+    // fill cluster
+    FillCluster(cluster,1);
+  }
+  
+  // set the fitting methods in the derived classes 
+  
+protected:
+  AliITSresponse         *fResponse;      // response
+  AliITSsegmentation     *fSegmentation;  //segmentation
+  
+  Int_t                   fNRawClusters;  // in case we split the cluster
+                                          // and want to keep track of 
+                                          // the cluster which was splitted
+  AliITSMap              *fMap;           // map
+  
+  Int_t                   fNperMax;       // NperMax
+  Int_t                   fDeclusterFlag; // DeclusterFlag
+  Int_t                   fClusterSize;   // ClusterSize
+  Int_t                   fNPeaks;        // NPeaks
+  
+  
+  ClassDef(AliITSClusterFinder,1) //Class for clustering and reconstruction of space points
+    };
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSClusterFinderSDD.cxx b/ITS/AliITSClusterFinderSDD.cxx
new file mode 100644 (file)
index 0000000..9db6c59
--- /dev/null
@@ -0,0 +1,417 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+#include "AliITSClusterFinderSDD.h"
+#include "AliRun.h"
+
+
+
+ClassImp(AliITSClusterFinderSDD)
+
+//----------------------------------------------------------
+AliITSClusterFinderSDD::AliITSClusterFinderSDD
+(AliITSsegmentation *seg, AliITSresponse *response, TClonesArray *digits, TClonesArray *recp)   
+{
+  // constructor
+    fSegmentation=seg;
+    fResponse=response;
+    fDigits=digits;
+    fClusters=recp;
+    fNclusters= fClusters->GetEntriesFast();
+    printf("SDD: fNclusters %d\n",fNclusters);
+    SetCutAmplitude();
+    SetDAnode();
+    SetDTime();
+    SetMap();
+    SetMinPeak();
+    SetNCells();
+}
+
+//_____________________________________________________________________________
+AliITSClusterFinderSDD::AliITSClusterFinderSDD()
+{
+  // constructor
+    fSegmentation=0;
+    fResponse=0;
+    fDigits=0;
+    fClusters=0;
+    fNclusters=0;
+    SetCutAmplitude();
+    SetDAnode();
+    SetDTime();
+    SetMap();
+    SetMinPeak();
+    SetNCells();
+
+}
+
+//__________________________________________________________________________
+AliITSClusterFinderSDD::AliITSClusterFinderSDD(const AliITSClusterFinderSDD &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fClusters = source.fClusters ;
+  this->fNclusters = source.fNclusters ;
+  this->fMap = source.fMap ;
+  this->fCutAmplitude = source.fCutAmplitude ;
+  this->fDAnode = source.fDAnode ;
+  this->fDTime = source.fDTime ;
+  this->fMinPeak = source.fMinPeak ;
+  this->fMinNCells = source.fMinNCells ;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSClusterFinderSDD& 
+  AliITSClusterFinderSDD::operator=(const AliITSClusterFinderSDD &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fClusters = source.fClusters ;
+  this->fNclusters = source.fNclusters ;
+  this->fMap = source.fMap ;
+  this->fCutAmplitude = source.fCutAmplitude ;
+  this->fDAnode = source.fDAnode ;
+  this->fDTime = source.fDTime ;
+  this->fMinPeak = source.fMinPeak ;
+  this->fMinNCells = source.fMinNCells ;
+  return *this;
+}
+
+//_____________________________________________________________________________
+void AliITSClusterFinderSDD::SetMap()
+{
+  // set map
+    if(!fMap) fMap=new AliITSMapA2(fSegmentation);
+
+}
+//_____________________________________________________________________________
+void AliITSClusterFinderSDD::FillMap()
+{
+  // fCoord1 = anode #
+  // fCoord2 = time sample
+
+  if (!fDigits) return; 
+  Int_t ndigits = fDigits->GetEntriesFast();
+  //printf("FillMap: ndigits %d\n",ndigits);
+  if (!ndigits) return;
+
+    AliITSdigitSDD *dig;
+    Int_t ndig;
+    for(ndig=0; ndig<ndigits; ndig++) {
+        dig = (AliITSdigitSDD*)fDigits->UncheckedAt(ndig);
+        Double_t signal=dig->fSignal;
+       //printf("FillMap: ndig fCoord1 fCoord2 signal %d %d %d %f\n",ndig,dig->fCoord1,dig->fCoord2,signal);
+        fMap->SetHit(dig->fCoord1,dig->fCoord2,signal);
+    }
+
+
+}
+//_____________________________________________________________________________
+
+void AliITSClusterFinderSDD::Find1DClusters()
+{
+  // find 1D clusters
+
+    AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
+
+   // retrieve the parameters 
+   Int_t fNofMaps = fSegmentation->Npz();
+   Int_t fMaxNofSamples = fSegmentation->Npx();
+   Int_t fNofAnodes = fNofMaps/2;
+   Int_t dummy=0;
+   Float_t fTimeStep = fSegmentation->Dpx(dummy);
+   Float_t fSddLength = fSegmentation->Dx();
+   Float_t fDriftSpeed = fResponse->DriftSpeed();
+   
+   Float_t anodePitch = fSegmentation->Dpz(dummy);
+   // map the signal
+   FillMap();
+
+   // Piergiorgio's code - do not subtract baseline since we start
+   // from digits and do not duplicate arrays, i.e. use fMap instead
+   // of Float_t fadc[2*fNofAnodes][fMaxNofSamples];
+
+  Int_t nofFoundClusters = 0;
+  Float_t dfadc[fNofMaps][fMaxNofSamples];
+  Float_t fadc, fadc1, fadc2;
+  Int_t j,k,idx,l,m;
+  for(j=0;j<2;j++) {
+    for(k=0;k<fNofAnodes;k++) {
+      idx = j*fNofAnodes+k;
+      // signal (fadc) & derivative (dfadc)
+      for(l=0; l<fMaxNofSamples; l++) {
+       fadc2=(Float_t)fMap->GetSignal(idx,l);
+       fadc1=(Float_t)fMap->GetSignal(idx,l-1);
+       if(l>0) dfadc[k][l-1] = fadc2-fadc1;
+      } // samples
+    } // anodes
+    
+    for(k=0;k<fNofAnodes;k++) {
+      idx = j*fNofAnodes+k;
+      Int_t imax = 0;
+      Int_t imaxd = 0;
+      Int_t it=0;
+      while(it <= fMaxNofSamples-3) {
+       //      cout << "sample: " << it << endl;
+       
+       imax = it;
+       imaxd = it;
+       // maximum of signal      
+       
+       Float_t fadcmax = 0.;
+       Float_t dfadcmax = 0.;
+       Int_t lthrmina = 1;
+       //      if(it >= 60) lthrmina = 2;
+        //      if(it >= 100) lthrmina = 3;
+       Int_t lthrmint = 2;
+       //if(it >= 60) lthrmint = 3;
+        //if(it >= 100) lthrmint = 4;
+
+       Int_t lthra = 0;
+       Int_t lthrt = 0;
+       for(m=0;m<10;m++) {
+         Int_t id = it+m;
+         if(id>=fMaxNofSamples) break;
+          fadc=fMap->GetSignal(idx,id);
+         if(fadc > fadcmax) {
+           fadcmax = fadc;
+           if(fadc > fCutAmplitude) { lthra++; lthrt++; }
+           imax = id;
+         }
+         if(dfadc[k][id] > dfadcmax) {
+           dfadcmax = dfadc[k][id];
+           imaxd = id;
+         }
+       }
+       it = imaxd;
+       // skip if no signal over threshold
+       if(fMap->GetSignal(idx,imax) < fCutAmplitude) {it++; continue;}
+
+       if(k>0) {
+         if(fMap->GetSignal(idx-1,imax) > fCutAmplitude) lthra++;
+       }
+       if(k<fNofAnodes-1)
+         if(fMap->GetSignal(idx+1,imax) > fCutAmplitude) lthra++;
+
+       if(imax>0) {
+         if(fMap->GetSignal(idx,imax-1) > fCutAmplitude) lthrt++;
+       }
+       if(imax<fMaxNofSamples)
+         if(fMap->GetSignal(idx,imax+1) > fCutAmplitude) lthrt++;
+       
+       // cluster charge
+       Int_t tstart = it-1;
+       
+       Bool_t ilcl = 0;
+       if(lthrt >= lthrmint && lthra >= lthrmina) ilcl = 1;
+       
+       if(ilcl) {
+         nofFoundClusters++;
+         Int_t tstop = tstart;
+         Float_t dfadcmin = 10000.;
+          Int_t ij;
+         for(ij=0; ij<10; ij++) {
+           if(dfadc[k][it+ij] < dfadcmin) {
+             tstop = it+ij+1;
+             dfadcmin = dfadc[k][it+ij];
+           }
+         }
+         
+         Float_t clusterCharge = 0.;
+         Float_t clusterAnode = k+0.5;
+         Float_t clusterTime = 0.;
+         Float_t clusterMult = 0.;
+         Float_t clusterPeakAmplitude = 0.;
+          Int_t its;
+         for(its=tstart; its<=tstop; its++) {
+            fadc=fMap->GetSignal(idx,its);
+           clusterCharge += fadc;
+           if(fadc > clusterPeakAmplitude) clusterPeakAmplitude = fadc;
+           clusterTime += fadc*its;
+           clusterMult++;
+           if(its == tstop) {
+              clusterTime /= (clusterCharge/fTimeStep);   // ns
+              clusterCharge *= (fTimeStep/160.);          // keV
+              if(clusterTime > 58.2) clusterTime -= 58.2;   // ns
+             /*
+             else {
+               cout << "Warning: cluster with negative time " << clusterTime << ", peak ampl.: " << clusterPeakAmplitude << ", mult: " << clusterMult << ", charge: " << clusterCharge << endl;
+               cout << "Anode: " << k << ", tstart: " << tstart << ", tstop: " << tstop << ", Charge: " << clusterCharge << endl;
+             }
+             */
+             }
+         }
+         // cout << "Anode: " << k << ", tstart: " << tstart << ", tstop: " << tstop << ", Charge: " << clusterCharge << endl;
+
+         Float_t clusteranodePath = (0.06 + clusterAnode - fNofAnodes/2)*anodePitch;
+         Float_t clusterDriftPath = clusterTime*fDriftSpeed;
+         clusterDriftPath = fSddLength-clusterDriftPath;
+
+          if(clusterCharge < 0.) break;
+
+         //printf("wing clusterMult clusterAnode clusterTime %d %f %f %f \n",j+1,clusterMult, clusterAnode, clusterTime);
+
+         AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(j+1,clusterAnode,clusterTime,clusterCharge,clusterPeakAmplitude,0.,0.,clusterDriftPath,clusteranodePath,clusterMult);
+         //fClusters->Add(point);
+         iTS->AddCluster(1,clust);
+         it = tstop;
+       } // ilcl
+       
+       it++;
+       
+      } // while (samples)
+    } // anodes
+  } // detectors (2)
+
+  Int_t nofClusters = fClusters->GetEntriesFast();
+  nofClusters -= fNclusters;
+
+  //printf("SDD- Find1Dclust: fNclusters nofClusters %d %d \n",fNclusters, nofClusters);
+
+  fMap->ClearMap();
+
+  return;
+
+}
+
+//_____________________________________________________________________________
+void  AliITSClusterFinderSDD::GroupClusters()
+{
+  // group clusters
+  Int_t dummy=0;
+  Float_t fTimeStep = fSegmentation->Dpx(dummy);
+
+
+  // get number of clusters for this module
+  Int_t nofClusters = fClusters->GetEntriesFast();
+  nofClusters -= fNclusters;
+
+  //printf("SDD- GroupClusters: fNclusters nofClusters %d %d \n",fNclusters, nofClusters);
+
+  AliITSRawClusterSDD *clusterI;
+  AliITSRawClusterSDD *clusterJ;
+
+  Int_t label[nofClusters];
+  Int_t i,j;
+  for(i=0; i<nofClusters; i++) label[i] = 0;
+  for(i=0; i<nofClusters; i++) { 
+    if(label[i] != 0) continue;
+    for(j=i+1; j<nofClusters; j++) { 
+      if(label[j] != 0) continue;
+      clusterI = (AliITSRawClusterSDD*) fClusters->At(i);
+      clusterJ = (AliITSRawClusterSDD*) fClusters->At(j);
+      // 1.3 good
+      if(clusterI->T() < fTimeStep*60) fDAnode = 3.2;
+      if(clusterI->T() < fTimeStep*10) fDAnode = 1.2;
+      Bool_t pair = clusterI->Brother(clusterJ,fDAnode,fDTime);
+      if(!pair) continue;
+      //      clusterI->Print();
+      //      clusterJ->Print();
+      clusterI->Add(clusterJ);
+      label[j] = 1;
+      fClusters->RemoveAt(j);
+    } // J clusters  
+    label[i] = 1;
+  } // I clusters
+  fClusters->Compress();
+  return;
+
+}
+
+//_____________________________________________________________________________
+
+void AliITSClusterFinderSDD::SelectClusters()
+{
+  // get number of clusters for this module
+  Int_t nofClusters = fClusters->GetEntriesFast();
+  nofClusters -= fNclusters;
+
+  //printf("SDD- SelectClusters: fNclusters nofClusters %d %d \n",fNclusters, nofClusters);
+
+  Int_t i;
+  for(i=0; i<nofClusters; i++) { 
+    AliITSRawClusterSDD *clusterI = (AliITSRawClusterSDD*) fClusters->At(i);
+    Int_t rmflg = 0;
+    Float_t wy = 0.;
+    if(clusterI->Anodes() != 0.) {
+      wy = ((Float_t) clusterI->Samples())/clusterI->Anodes();
+    }
+    Float_t amp = clusterI->PeakAmpl();
+    if(amp < fMinPeak) rmflg = 1;  
+    if(wy < fMinNCells) rmflg = 1;
+    if(rmflg) fClusters->RemoveAt(i);
+  } // I clusters
+  fClusters->Compress();
+  return;
+
+}
+
+//_____________________________________________________________________________
+
+void AliITSClusterFinderSDD::GetRecPoints()
+{
+  // get rec points
+  //static Int_t counter=0;
+
+  AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
+
+  // get number of clusters for this module
+  Int_t nofClusters = fClusters->GetEntriesFast();
+  nofClusters -= fNclusters;
+
+  //printf("SDD- GetRecPoints: fNclusters nofClusters %d %d \n",fNclusters, nofClusters);
+
+//  const Float_t kdEdXtoQ = 2.778e+2; // KeV -> number of e-hole pairs in Si
+  const Float_t kconvGeV = 1.e-6; // GeV -> KeV
+  const Float_t kconv = 1.0e-4; 
+  const Float_t kRMSx = 38.0*kconv; // microns->cm ITS TDR Table 1.3
+  const Float_t kRMSz = 28.0*kconv; // microns->cm ITS TDR Table 1.3
+
+  Int_t i;
+  for(i=0; i<nofClusters; i++) { 
+    AliITSRawClusterSDD *clusterI = (AliITSRawClusterSDD*) fClusters->At(i);
+    AliITSRecPoint rnew;
+    rnew.SetX(clusterI->X());
+    rnew.SetZ(clusterI->Z());
+    rnew.SetQ(clusterI->Q());   // in KeV - should be ADC
+    //rnew.SetdEdX((clusterI->Q())/kdEdXtoQ);
+    rnew.SetdEdX(kconvGeV*clusterI->Q());
+    rnew.SetSigmaX2(kRMSx*kRMSx);
+    rnew.SetSigmaZ2(kRMSz*kRMSz);
+    rnew.SetProbability(1.);
+    iTS->AddRecPoint(rnew);
+   //counter++;
+  } // I clusters
+  //printf("counter %d\n",counter);
+
+}
+
+//_____________________________________________________________________________
+
+void AliITSClusterFinderSDD::FindRawClusters()
+{
+  // find raw clusters
+    Find1DClusters();
+    GroupClusters();
+    SelectClusters();
+    GetRecPoints();
+}
+
+
+
+
diff --git a/ITS/AliITSClusterFinderSDD.h b/ITS/AliITSClusterFinderSDD.h
new file mode 100644 (file)
index 0000000..f2c5a48
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef ALIITSCLUSTERFINDERSDD_H
+#define ALIITSCLUSTERFINDERSDD_H
+
+////////////////////////////////////////////////
+//  ITS Cluster Finder Class                 //
+////////////////////////////////////////////////
+
+#include "AliITSClusterFinder.h"
+
+class AliITSClusterFinderSDD :
+ public AliITSClusterFinder
+
+{
+public:
+  AliITSClusterFinderSDD
+  (AliITSsegmentation *seg, 
+   AliITSresponse *response, TClonesArray *digits,TClonesArray *recpoints);
+  AliITSClusterFinderSDD();
+  virtual ~AliITSClusterFinderSDD(){
+    // destructor
+  }
+  AliITSClusterFinderSDD(const AliITSClusterFinderSDD &source); // copy constructor
+  AliITSClusterFinderSDD& operator=(const AliITSClusterFinderSDD &source); // assignment operator
+  
+  virtual void SetMap();
+  virtual void SetCutAmplitude(Float_t thres=1.2) {
+    // set cut amplitude
+    fCutAmplitude=thres;
+  }
+  virtual void SetDAnode(Float_t danode=4.2) {
+    // setDAnode
+    fDAnode=danode;
+  }
+  virtual void SetDTime(Float_t dtime=75) {
+    // SetDTime
+    fDTime=dtime;
+  }
+  virtual void SetMinPeak(Int_t minpeak=7) {
+    // SetMinPeak
+    fMinPeak=minpeak;
+  }
+  virtual void SetNCells(Int_t minc=4) {
+    // setNCells
+    fMinNCells=minc;
+  }
+  
+  void FillMap();
+  
+  // Search for clusters
+  virtual void FindRawClusters();
+  void  Find1DClusters();
+  void  GroupClusters();
+  void  SelectClusters();
+  void  GetRecPoints();
+  
+private:
+  
+  TClonesArray       *fClusters;      // clusters
+  Int_t               fNclusters;     // num of clusters
+  AliITSMapA2        *fMap;           // map
+  Float_t             fCutAmplitude;  // cut amplitude
+  Float_t             fDAnode;        // fDanode
+  Float_t             fDTime;         // fDtime
+  
+  Int_t               fMinPeak;       // min peak
+  Int_t               fMinNCells;     // min num of cells
+  
+  
+  ClassDef(AliITSClusterFinderSDD,1) // SDD clustering - Piergiorgio C. algo
+    };
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSClusterFinderSPD.cxx b/ITS/AliITSClusterFinderSPD.cxx
new file mode 100644 (file)
index 0000000..f45c235
--- /dev/null
@@ -0,0 +1,304 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+#include "AliITSClusterFinderSPD.h"
+#include "AliRun.h"
+
+
+
+ClassImp(AliITSClusterFinderSPD)
+
+//----------------------------------------------------------
+AliITSClusterFinderSPD::AliITSClusterFinderSPD
+(AliITSsegmentation *seg, TClonesArray *digits, TClonesArray *recp)   
+{
+  // constructor
+    fSegmentation=seg;
+    fDigits=digits;
+    fClusters=recp;
+    fNclusters= fClusters->GetEntriesFast();
+    SetDx();
+    SetDz();
+    SetMap();
+    SetNCells();
+}
+
+//_____________________________________________________________________________
+AliITSClusterFinderSPD::AliITSClusterFinderSPD()
+{
+  // constructor
+  fSegmentation=0;
+  fDigits=0;
+  fClusters=0;
+  fNclusters=0;
+  SetDx();
+  SetDz();
+  SetMap();
+  SetNCells();
+  
+}
+
+//__________________________________________________________________________
+AliITSClusterFinderSPD::AliITSClusterFinderSPD(const AliITSClusterFinderSPD &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fClusters = source.fClusters ;
+  this->fNclusters = source.fNclusters ;
+  this->fMap = source.fMap ;
+  this->fDz = source.fDz ;
+  this->fDx = source.fDx ;
+  this->fMinNCells = source.fMinNCells ;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSClusterFinderSPD& 
+  AliITSClusterFinderSPD::operator=(const AliITSClusterFinderSPD &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fClusters = source.fClusters ;
+  this->fNclusters = source.fNclusters ;
+  this->fMap = source.fMap ;
+  this->fDz = source.fDz ;
+  this->fDx = source.fDx ;
+  this->fMinNCells = source.fMinNCells ;
+  return *this;
+}
+
+//_____________________________________________________________________________
+void AliITSClusterFinderSPD::SetMap()
+{
+  // set map
+  if(!fMap) fMap=new AliITSMapA1(fSegmentation,fDigits);
+  
+}
+
+//_____________________________________________________________________________
+
+void AliITSClusterFinderSPD::Find1DClusters()
+{
+  // Find one dimensional clusters, i.e.
+  // in r*phi(x) direction for each colunm in z direction
+  
+  AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
+  
+  // retrieve the parameters 
+  Int_t fNofPixels = fSegmentation->Npz(); 
+  Int_t fMaxNofSamples = fSegmentation->Npx();
+  
+  // read in digits -> do not apply threshold 
+  // signal in fired pixels is always 1
+  fMap->FillMap();
+  
+  Int_t nofFoundClusters = 0;
+  
+  Int_t k,it,m;
+  for(k=0;k<fNofPixels;k++) {
+    
+    Int_t mmax = 10;  // a size of the window for the cluster finding
+    
+    for(it=0;it<fMaxNofSamples;it++) {
+      
+      Int_t lclx = 0;
+      Int_t xstart = 0;
+      Int_t xstop = 0;
+      Int_t id = 0;
+      Int_t ilcl =0;
+      
+      for(m=0;m<mmax;m++) {  // find the cluster inside the window
+       id = it+m;
+       if(id >= fMaxNofSamples) break;    // ! no possible for the fadc 
+       
+       if(fMap->GetHitIndex(k,id)) {   // start of the cluster
+         lclx += 1;
+         if(lclx == 1) xstart = id;
+         
+       }
+       
+       if(lclx > 0 && !fMap->GetHitIndex(k,id)) {  
+         // end of cluster if a gap exists
+         xstop = id-1;
+         ilcl = 1;
+         break;
+       }            
+       
+      }   //  end of m-loop
+      
+      if(lclx == 0 && ilcl == 0) it = id; // no cluster in the window,
+      // continue the "it" loop
+      
+      if(id >= fMaxNofSamples && lclx == 0) break; // the x row finished
+      
+      if(id < fMaxNofSamples && ilcl == 0 && lclx > 0) {  
+       // cluster end is outside of the window,
+       mmax += 5;                 // increase mmax and repeat the cluster
+       // finding
+       it -= 1;
+      }
+      
+      if(id >= fMaxNofSamples && lclx > 0) {  // the x row finished but
+       xstop = fMaxNofSamples - 1;          // the end cluster exists
+       ilcl = 1;
+      } 
+      
+      // ---  Calculate z and x coordinates for one dimensional clusters
+      
+      if(ilcl == 1) {         // new cluster exists
+       it = id;
+       mmax = 10;
+           nofFoundClusters++;
+           Float_t clusterCharge = 0.;
+            // get this from segmentation when this will be implemented
+            Float_t zpitch = fSegmentation->Dpz(k+1); 
+           Float_t clusterZ, dummyX; 
+            Int_t dummy=0;
+            fSegmentation->GetCellCxz(dummy,k,dummyX,clusterZ);
+            Float_t zstart = clusterZ - 0.5*zpitch;
+            Float_t zstop = clusterZ + 0.5*zpitch;
+           Float_t clusterX = 0.;
+            Int_t xstartfull = xstart;
+            Int_t xstopfull = xstop;
+           Int_t clusterSizeX = lclx;
+           Int_t clusterSizeZ = 1;
+           
+            Int_t its;
+           for(its=xstart; its<=xstop; its++) {
+              Int_t firedpixel=0;
+              if (fMap->GetHitIndex(k,its)) firedpixel=1; 
+             clusterCharge += firedpixel;
+              clusterX +=its + 0.5;
+           }
+            Float_t fRphiPitch = fSegmentation->Dpx(dummy);
+           clusterX /= (clusterSizeX/fRphiPitch); // center of gravity for x 
+           
+           
+           //printf("ClusterZ ClusterX %f %f \n",clusterZ, clusterX);
+           
+            // Int_t nclusters = fClusters->GetEntriesFast();
+           //              cout << nclusters << " clusters" << endl;
+           //            cout<< "Create point"<<endl;
+           
+           // Write the points (coordinates and some cluster information) to the
+           // AliITSRawClusterSPD object
+           
+           AliITSRawClusterSPD *clust = new AliITSRawClusterSPD(clusterZ,clusterX,clusterCharge,clusterSizeZ,clusterSizeX,xstart,xstop,xstartfull,xstopfull,zstart,zstop,k);
+           // fClusters->Add(point);
+           iTS->AddCluster(0,clust);
+           //              cout << "Cluster at Ladder: " << fLadder << ", Detector: " <<fDetector<<endl;
+           
+           // cout<<" end of cluster finding for Z pixel "<<endl;
+           
+      }    // new cluster (ilcl=1)
+    } // X direction loop (it)
+  } // Z direction loop (k)
+  return;
+  
+}
+
+//_____________________________________________________________________________
+void  AliITSClusterFinderSPD::GroupClusters()
+{
+  // Find two dimensional clusters, i.e. group one dimensional clusters
+  // into two dimensional ones (go both in x and z directions).
+  
+  // get number of clusters for this module
+  Int_t nofClusters = fClusters->GetEntriesFast();
+  nofClusters -= fNclusters;
+  //printf("Group: fNclusters nofClusters %d %d\n",fNclusters, nofClusters);
+  
+  AliITSRawClusterSPD *clusterI;
+  AliITSRawClusterSPD *clusterJ;
+  
+  //Int_t *label=new Int_t[nofClusters];  // activate this for DEC machines
+  Int_t label[nofClusters];   
+  Int_t i,j;
+  for(i=0; i<nofClusters; i++) label[i] = 0;
+  for(i=0; i<nofClusters; i++) {
+    if(label[i] != 0) continue;
+    for(j=i+1; j<nofClusters; j++) { 
+      if(label[j] != 0) continue;
+      clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
+      clusterJ = (AliITSRawClusterSPD*) fClusters->At(j);
+      Bool_t pair = clusterI->Brother(clusterJ,fDz,fDx);
+      if(pair) {     
+       
+       //    if((clusterI->XStop() == clusterJ->XStart()-1)||(clusterI->XStart()==clusterJ->XStop()+1)) cout<<"!! Diagonal cluster"<<endl;
+       /*    
+             cout << "clusters " << i << "," << j << " before grouping" << endl;
+             clusterI->Print();
+             clusterJ->Print();
+       */    
+       clusterI->Add(clusterJ);
+       //        cout << "remove cluster " << j << endl;
+       label[j] = 1;
+       fClusters->RemoveAt(j);
+       /*
+         cout << "cluster  " << i << " after grouping" << endl;
+         clusterI->Print();
+       */
+      }  // pair
+    } // J clusters  
+    label[i] = 1;
+  } // I clusters
+  fClusters->Compress();
+  //Int_t totalNofClusters = fClusters->GetEntriesFast();
+  //cout << " Nomber of clusters at the group end ="<< totalNofClusters<<endl;
+  
+  return;
+  
+  
+}
+//_____________________________________________________________________________
+
+void AliITSClusterFinderSPD::GetRecPoints()
+{
+  // get rec points
+  AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
+  
+  // get number of clusters for this module
+  Int_t nofClusters = fClusters->GetEntriesFast();
+  nofClusters -= fNclusters;
+  //printf("GetRecP: fNclusters nofClusters %d %d\n",fNclusters, nofClusters);
+  
+  const Float_t kconv = 1.0e-4;
+  const Float_t kRMSx = 12.0*kconv; // microns -> cm ITS TDR Table 1.3
+  const Float_t kRMSz = 70.0*kconv; // microns -> cm ITS TDR Table 1.3
+
+  Int_t i;
+  for(i=0; i<nofClusters; i++) { 
+    AliITSRawClusterSPD *clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
+    AliITSRecPoint rnew;
+    rnew.SetX(clusterI->X()*kconv);
+    rnew.SetZ(clusterI->Z()*kconv);
+    rnew.SetQ(1.);
+    rnew.SetdEdX(0.);
+    rnew.SetSigmaX2(kRMSx*kRMSx);
+    rnew.SetSigmaZ2(kRMSz*kRMSz);
+    rnew.SetProbability(1.);
+    iTS->AddRecPoint(rnew);
+  } // I clusters
+  
+}
+//_____________________________________________________________________________
+
+void AliITSClusterFinderSPD::FindRawClusters()
+{
+  // find raw clusters
+  Find1DClusters();
+  GroupClusters();
+  GetRecPoints();
+}
+
diff --git a/ITS/AliITSClusterFinderSPD.h b/ITS/AliITSClusterFinderSPD.h
new file mode 100644 (file)
index 0000000..89d2ce3
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef ALIITSCLUSTERFINDERSPD_H
+#define ALIITSCLUSTERFINDERSPD_H
+
+////////////////////////////////////////////////
+//  ITS Cluster Finder Class                 //
+////////////////////////////////////////////////
+
+#include "AliITSClusterFinder.h"
+
+class AliITSClusterFinderSPD :
+  public AliITSClusterFinder
+
+{
+public:
+  AliITSClusterFinderSPD
+  (AliITSsegmentation *segmentation,
+   TClonesArray *digits, TClonesArray *recpoints);
+  AliITSClusterFinderSPD();
+  virtual ~AliITSClusterFinderSPD(){
+    // destructor
+  }
+  AliITSClusterFinderSPD(const AliITSClusterFinderSPD &source); // copy constructor
+  AliITSClusterFinderSPD& operator=(const AliITSClusterFinderSPD &source); // assignment operator
+  
+  virtual void SetMap();
+  virtual void SetDx(Float_t dx=1.) {
+    // set dx
+    fDx=dx;
+  }
+  virtual void SetDz(Float_t dz=0.) {
+    // set dz
+    fDz=dz;
+  }
+  virtual void SetNCells(Int_t minc=0) {
+    // set ncells
+    fMinNCells=minc;
+  }
+  
+  // Search for clusters
+  virtual void FindRawClusters();
+  void  Find1DClusters();
+  void  GroupClusters();
+  void  SelectClusters() {
+    // selects clusters
+  }
+  void  GetRecPoints();
+  
+private:
+  
+  TClonesArray       *fClusters;      // clusters
+  Int_t               fNclusters;     // num of clusters
+  AliITSMapA1        *fMap;           // map
+  Float_t             fDz;            // dz
+  Float_t             fDx;            // dx
+  
+  Int_t               fMinNCells;     // min num of cells
+  
+  ClassDef(AliITSClusterFinderSPD,1)  // SPD clustering - Boris B. algo based
+    // on Piergiorgio's algo
+    };
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSClusterFinderSSD.cxx b/ITS/AliITSClusterFinderSSD.cxx
new file mode 100644 (file)
index 0000000..e843459
--- /dev/null
@@ -0,0 +1,2024 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+
+Adding rekonstruction facilities
+Piotr Krzysztof Skowronski 
+December 1999.
+*/
+
+/*
+15 -18 V 2000
+Eroor counting routines
+Automatic combination routines improved (traps)
+
+*/
+
+#include "AliRun.h"
+#include "AliITSClusterFinderSSD.h"
+
+const Int_t debug=0;
+
+ClassImp(AliITSClusterFinderSSD)
+
+//____________________________________________________________________
+//
+//  Constructor
+//____________________________________________________________________
+//                                     
+
+
+AliITSClusterFinderSSD::AliITSClusterFinderSSD(AliITSsegmentation *seg, TClonesArray *digits, TClonesArray *recp)   
+{
+
+    fSegmentation=seg;
+    fDigits=digits;
+    fRecPoints=recp;
+    
+    fITS=(AliITS*)gAlice->GetModule("ITS");
+    
+    fClusterP =  new TClonesArray ("AliITSclusterSSD",200);    
+    fNClusterP =0;   
+    
+    fClusterN=  new TClonesArray ("AliITSclusterSSD",200);   
+    fNClusterN =0; 
+
+    fPackages =  new TClonesArray ("AliITSpackageSSD",200);    //packages  
+    fNPackages = 0;
+
+        
+    fDigitsIndexP      =  new TArrayI(300);
+    fNDigitsP          =  0;
+    
+    fDigitsIndexN      =  new TArrayI(300);
+    fNDigitsN          =  0;
+    
+    SetAlpha1(1000);
+    SetAlpha2(1000);
+    SetAlpha3(1000);
+
+    
+    fPitch = fSegmentation->Dpx(0);
+    Float_t StereoP,StereoN;
+    fSegmentation->Angles(StereoP,StereoN);
+    fTanP=TMath::Tan(StereoP);
+    fTanN=TMath::Tan(StereoN);
+
+}
+
+//-------------------------------------------------------
+AliITSClusterFinderSSD::~AliITSClusterFinderSSD() {
+   
+    delete fClusterP;
+    delete fClusterN;        
+    delete fPackages;        
+    delete fDigitsIndexP;        
+    delete fDigitsIndexN; 
+}
+
+//-------------------------------------------------------
+void AliITSClusterFinderSSD::InitReconstruction()
+{
+
+  register Int_t i; //iterator
+
+  for(i=0;i<fNClusterP;i++)
+    {
+      fClusterP->RemoveAt(i);
+    }
+  fNClusterP  =0;
+  for(i=0;i<fNClusterN;i++)
+    {
+      fClusterN->RemoveAt(i);
+    }
+  fNClusterN=0;
+
+  for(i=0;i<fNPackages;i++)
+    {
+      fPackages->RemoveAt(i);
+    }
+
+  fNPackages = 0;
+  fNDigitsP=0;
+  fNDigitsN=0;
+
+  Float_t StereoP,StereoN;
+  fSegmentation->Angles(StereoP,StereoN);
+
+  CalcStepFactor (StereoP,StereoN);
+
+  if (debug) cout<<"fSFF = "<<fSFF<<"  fSFB = "<<fSFB<<"\n";
+}
+
+
+//---------------------------------------------
+void AliITSClusterFinderSSD::FindRawClusters() 
+{
+
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+// This function findes out all clusters belonging to one module
+// 1. Zeroes all space after previous module reconstruction
+// 2. Finds all neighbouring digits
+// 3. If necesery, resolves for each group of neighbouring digits 
+//    how many clusters creates it.
+// 4. Creates packages  
+// 5. Creates clusters 
+
+  InitReconstruction();  //ad. 1
+  FillDigitsIndex();
+  SortDigits();
+  FindNeighbouringDigits(); //ad. 2
+  SeparateOverlappedClusters();  //ad. 3
+  ClustersToPackages();  //ad. 4
+  ConsumeClusters();
+  PackagesToPoints();   //ad. 5
+  ReconstructNotConsumedClusters();
+}
+
+
+//-------------------------------------------------
+void AliITSClusterFinderSSD::FindNeighbouringDigits()
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+ register Int_t i;
+
+    //If there are any digits on this side, create 1st Cluster,
+    // add to it this digit, and increment number of clusters
+
+ if ((fNDigitsP>0 )  && (fNDigitsN > 0 )) {     
+
+   Int_t currentstripNo;
+   Int_t *dbuffer = new Int_t [300];   //buffer for strip numbers
+   Int_t dnumber;    //curent number of digits in buffer
+   TArrayI &lDigitsIndexP = *fDigitsIndexP;
+   TArrayI &lDigitsIndexN = *fDigitsIndexN;
+   TObjArray &lDigits=*fDigits;
+   TClonesArray &lClusterP = *fClusterP;
+   TClonesArray &lClusterN = *fClusterN;
+  
+   //process P side 
+   dnumber = 1;
+   dbuffer[0]=lDigitsIndexP[0];
+   //If next digit is a neighbour of previous, adds to last cluster this digit
+   for(i=1; i<fNDigitsP; i++) {
+     //reads new digit
+     currentstripNo = ((AliITSdigitSSD*)lDigits[lDigitsIndexP[i]])->
+                                                            GetStripNumber(); 
+     //check if it is a neighbour of a previous one
+     if ( (((AliITSdigitSSD*)lDigits[lDigitsIndexP[i-1]])->GetStripNumber()) 
+           ==  (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexP[i];
+     else  { 
+       //create a new one side cluster
+       new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEP); 
+       dbuffer[0]=lDigitsIndexP[i];
+       dnumber = 1;
+     }
+   } // end loop over fNDigitsP
+   new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEP);
+
+
+   //process N side 
+   //for comments, see above
+   dnumber = 1;
+   dbuffer[0]=lDigitsIndexN[0];
+   //If next digit is a neighbour of previous, adds to last cluster this digit
+   for(i=1; i<fNDigitsN; i++) { 
+     currentstripNo = ((AliITSdigitSSD*)(lDigits[lDigitsIndexN[i]]))->
+                                                            GetStripNumber();
+     if ( (((AliITSdigitSSD*)lDigits[lDigitsIndexN[i-1]])->GetStripNumber()) 
+           == (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexN[i];
+     else {
+       new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEN);
+       dbuffer[0]=lDigitsIndexN[i];
+       dnumber = 1;
+     }
+   } // end loop over fNDigitsN
+   new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEN);
+   delete [] dbuffer; 
+ } // end condition on  NDigits 
+
+ if (debug) cout<<"\n Found clusters: fNClusterP = "<<fNClusterP<<"  fNClusterN ="<<fNClusterN<<"\n";
+
+}  
+/**********************************************************************/
+
+
+void AliITSClusterFinderSSD::SeparateOverlappedClusters()
+{
+//************************************************
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+  register Int_t i,j; //iterator
+
+  Float_t  factor=0.75;            // How many percent must be lower signal 
+                                   // on the middle one digit
+                                   // from its neighbours
+  Int_t    signal0;                //signal on the strip before the current one
+  Int_t    signal1;                //signal on the current one signal
+  Int_t    signal2;                //signal on the strip after the current one
+  TArrayI *splitlist;              //  List of splits
+  Int_t    numerofsplits=0;        // number of splits
+  Int_t    initPsize = fNClusterP; //initial size of the arrays 
+  Int_t    initNsize = fNClusterN; //we have to keep it because it will grow 
+                                   // in this function and it doasn't make 
+                                   // sense to pass through it again
+
+  splitlist = new TArrayI(300);
+
+  for(i=0;i<initPsize;i++)
+  {
+    if (( ((AliITSclusterSSD*)(*fClusterP)[i])->GetNumOfDigits())==1) continue;
+    if (( ((AliITSclusterSSD*)(*fClusterP)[i])->GetNumOfDigits())==2) continue;
+        Int_t nj=(((AliITSclusterSSD*)(*fClusterP)[i])->GetNumOfDigits()-1);
+        for(j=1; j<nj; j++)
+          {
+            signal1=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j);
+            signal0=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j-1);
+            signal2=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j+1);
+            //if signal is less then factor*signal of its neighbours
+            if (  (signal1<(factor*signal0)) && (signal1<(factor*signal2)) )
+             {                                                               
+               (*splitlist)[numerofsplits++]=j;  
+            }
+         } // end loop over number of digits
+          //split this cluster if necessary
+          if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,SIDEP); 
+         numerofsplits=0;
+
+         //in signed places (splitlist)
+  } // end loop over clusters on Pside
+
+  for(i=0;i<initNsize;i++) {
+    if (( ((AliITSclusterSSD*)(*fClusterN)[i])->GetNumOfDigits())==1) continue;
+    if (( ((AliITSclusterSSD*)(*fClusterN)[i])->GetNumOfDigits())==2) continue;
+       Int_t nj=(((AliITSclusterSSD*)(*fClusterN)[i])->GetNumOfDigits()-1);
+       for(j=1; j<nj; j++)
+          {
+            signal1=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j);
+            signal0=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j-1);
+            signal2=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j+1);
+            //if signal is less then factor*signal of its neighbours
+            if (  (signal1<(factor*signal0)) && (signal1<(factor*signal2)) ) 
+               (*splitlist)[numerofsplits++]=j;  
+          } // end loop over number of digits 
+          //split this cluster into more clusters
+          if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,SIDEN);
+         numerofsplits=0;                                                              //in signed places (splitlist)
+  } // end loop over clusters on Nside
+
+  delete splitlist;
+}
+
+//-------------------------------------------------------
+void AliITSClusterFinderSSD::SplitCluster(TArrayI *list, Int_t nsplits, Int_t index, Bool_t side)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+  //This function splits one side cluster into more clusters
+  //number of splits is defined by "nsplits"
+  //Place of splits are defined in the TArray "list" 
+  
+  // For further optimisation: Replace this function by two 
+  // specialised ones (each for one side)
+  // save one "if"
+
+  //For comlete comments see AliITSclusterSSD::SplitCluster
+
+
+  register Int_t i; //iterator
+
+  AliITSclusterSSD* curentcluster;
+  Int_t   *tmpdigits = new Int_t[100];
+  Int_t    NN;
+  // side true means P side
+  if (side) {
+     curentcluster =((AliITSclusterSSD*)((*fClusterP)[index])) ;
+     for(i = nsplits; i>0 ;i--) {  
+         NN=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits);
+         new ((*fClusterP)[fNClusterP]) AliITSclusterSSD(NN,tmpdigits,fDigits,side);
+        ( (AliITSclusterSSD*)((*fClusterP)[fNClusterP]) )->
+                                                      SetLeftNeighbour(kTRUE);
+         //if left cluster had neighbour on the right before split 
+        //new should have it too
+        if ( curentcluster->GetRightNeighbour() ) 
+                     ( (AliITSclusterSSD*)((*fClusterP)[fNClusterP]) )->
+                                                     SetRightNeighbour(kTRUE);
+         else curentcluster->SetRightNeighbour(kTRUE); 
+        fNClusterP++;
+     } // end loop over nplits
+  } else {
+     curentcluster =((AliITSclusterSSD*)((*fClusterN)[index]));
+     for(i = nsplits; i>0 ;i--) {  
+         NN=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits);
+        new ((*fClusterN)[fNClusterN]) AliITSclusterSSD(NN,tmpdigits,fDigits,side);
+        ((AliITSclusterSSD*)((*fClusterN)[fNClusterN]))->
+                                                    SetRightNeighbour(kTRUE);
+        if (curentcluster->GetRightNeighbour())
+                      ( (AliITSclusterSSD*)( (*fClusterN)[fNClusterN]) )->
+                                                     SetRightNeighbour(kTRUE);
+        else curentcluster->SetRightNeighbour(kTRUE);      
+        fNClusterN++;
+     } // end loop over nplits
+  } // end if side
+  delete []tmpdigits;
+
+}
+
+
+//-------------------------------------------------
+Int_t AliITSClusterFinderSSD::SortDigitsP(Int_t start, Int_t end)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+  
+  Int_t right;
+  Int_t left;
+  if (start != (end - 1) ) 
+    {
+      left=this->SortDigitsP(start,(start+end)/2);
+      right=this->SortDigitsP((start+end)/2,end);  
+      return (left || right);
+    }
+  else
+   { 
+    left =  ((AliITSdigitSSD*)((*fDigits)[(*fDigitsIndexP)[start]]))->GetStripNumber();
+    right= ((AliITSdigitSSD*)((*fDigits)[(*fDigitsIndexP)[end]]))->GetStripNumber();  
+    if( left > right )
+     {
+       Int_t tmp = (*fDigitsIndexP)[start];
+       (*fDigitsIndexP)[start]=(*fDigitsIndexP)[end];
+       (*fDigitsIndexP)[end]=tmp;
+       return 1;
+     }
+    else return 0;
+   }
+}
+
+
+//--------------------------------------------------
+
+Int_t AliITSClusterFinderSSD::SortDigitsN(Int_t start, Int_t end)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+  Int_t right;
+  Int_t left;
+  if (start != (end - 1)) 
+    {
+      left=this->SortDigitsN(start,(start+end)/2);
+      right=this->SortDigitsN((start+end)/2,end);  
+      return (left || right);
+    }
+  else 
+   {
+    left =((AliITSdigitSSD*)((*fDigits)[(*fDigitsIndexN)[start]]))->GetStripNumber(); 
+    right=((AliITSdigitSSD*)((*fDigits)[(*fDigitsIndexN)[end]]))->GetStripNumber();
+    if ( left > right )
+      {
+        Int_t tmp = (*fDigitsIndexN)[start];
+        (*fDigitsIndexN)[start]=(*fDigitsIndexN)[end];
+        (*fDigitsIndexN)[end]=tmp;
+        return 1;
+      }else return 0;
+   }  
+}
+
+
+//------------------------------------------------
+void AliITSClusterFinderSSD::FillDigitsIndex()
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+ //Fill the indexes of the clusters belonging to a given ITS module
+ //Created by Piotr K. Skowronski, August 7 1999
+
+ Int_t PNs=0, NNs=0;
+ Int_t tmp,bit,k;
+ Int_t N;
+ Int_t i;
+ N = fDigits->GetEntriesFast();
+
+ Int_t* PSidx = new Int_t [N*sizeof(Int_t)];
+ Int_t* NSidx = new Int_t [N*sizeof(Int_t)]; 
+ if (fDigitsIndexP==NULL) fDigitsIndexP = new TArrayI(N);
+ if (fDigitsIndexN==NULL) fDigitsIndexN = new TArrayI(N);
+ AliITSdigitSSD *dig; 
+ for(i = 0 ; i< N; i++ ) {
+      dig=(AliITSdigitSSD*)fDigits->UncheckedAt(i);
+      if(dig->IsSideP()) { 
+           bit=1;
+           tmp=dig->GetStripNumber();
+          // I find this totally unnecessary - it's just a 
+          // CPU consuming double check
+           for(k=0;k<PNs;k++)
+            {
+             if (tmp==PSidx[k])
+              {
+                 if (debug) cout<<"Such a digit exists \n";
+                 bit=0;
+              }
+           }   
+          // end comment 
+        if(bit) {
+            fDigitsIndexP->AddAt(i,fNDigitsP++);
+            PSidx[PNs++]=tmp;
+       }
+      } else {
+         bit=1;
+         tmp=dig->GetStripNumber();
+        // same as above
+         for(k=0;k<NNs;k++)
+          {
+           if (tmp==NSidx[k])
+            {
+             if (debug) cout<<"Such a digit exists \n";
+             bit=0;
+            }
+          } 
+        // end comment
+         if (bit) {
+          fDigitsIndexN->AddAt(i,fNDigitsN++);
+          NSidx[NNs++] =tmp;
+        }
+      }
+ }
+   
+
+ if (debug) cout<<"Digits :  P = "<<fNDigitsP<<"   N = "<<fNDigitsN<<endl;
+
+}
+
+
+//-------------------------------------------
+
+void AliITSClusterFinderSSD::SortDigits()
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+
+
+  Int_t i;
+  if(fNDigitsP>1) 
+  for(i=0;i<fNDigitsP-1;i++)
+  if (SortDigitsP(0,(fNDigitsP-1-i))==0) break;
+
+  if(fNDigitsN>1) 
+    for(i=0;i<fNDigitsN-1;i++)
+  if(SortDigitsN(0,(fNDigitsN-1-i))==0) break;
+}
+
+
+
+//----------------------------------------------
+void AliITSClusterFinderSSD::FillClIndexArrays(Int_t* arrayP, Int_t *arrayN)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+
+  register Int_t i;
+  for(i=0; i<fNClusterP;i++)
+    {
+      arrayP[i]=i;
+    }
+  for(i=0; i<fNClusterN;i++)
+    {
+      arrayN[i]=i;
+    }
+}
+
+
+//------------------------------------------------------
+void AliITSClusterFinderSSD::SortClusters(Int_t* arrayP, Int_t *arrayN)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+
+  Int_t i;
+  if(fNClusterP>1) 
+    for(i=0;i<fNClusterP-1;i++)
+      if (SortClustersP(0,(fNClusterP-1),arrayP)==0)  break;
+    
+    
+  if(fNClusterN>1) 
+    for(i=0;i<fNClusterN-1;i++)
+      if (SortClustersN(0,(fNClusterN-1),arrayN)==0)  break;
+
+}
+
+
+
+//---------------------------------------------------
+Int_t AliITSClusterFinderSSD::SortClustersP(Int_t start, Int_t end, Int_t *array)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+
+
+  Int_t right;
+  Int_t left;
+  if (start != (end - 1) ) {
+      left=this->SortClustersP(start,(start+end)/2,array);
+      right=this->SortClustersP((start+end)/2,end,array);  
+      return (left || right);
+  } else {
+      left =((AliITSclusterSSD*)((*fClusterP)[array[start]]))->
+                                                         GetDigitStripNo(0);
+      right=((AliITSclusterSSD*)((*fClusterP)[array[ end ]]))->
+                                                         GetDigitStripNo(0);
+      if(left>right) {
+         Int_t tmp = array[start];
+        array[start]=array[end];
+        array[end]=tmp;
+        return 1;
+      } else return 0;
+  }
+
+}
+
+
+
+//-------------------------------------------------------
+Int_t AliITSClusterFinderSSD::SortClustersN(Int_t start, Int_t end, Int_t *array)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+  Int_t right;
+  Int_t left;
+  
+  if (start != (end - 1) ) {
+      left=this->SortClustersN(start,(start+end)/2,array);
+      right=this->SortClustersN((start+end)/2,end,array);  
+      return (left || right);
+  } else {
+      left =((AliITSclusterSSD*)((*fClusterN)[array[start]]))->
+                                                         GetDigitStripNo(0);
+      right=((AliITSclusterSSD*)((*fClusterN)[array[ end ]]))->
+                                                         GetDigitStripNo(0);
+      if( left > right) {
+         Int_t tmp = array[start];
+         array[start]=array[end];
+         array[end]=tmp;
+         return 1;
+      } else return 0;
+    } 
+
+}
+    
+
+
+//-------------------------------------------------------
+void AliITSClusterFinderSSD::ClustersToPackages()
+{  
+
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+  
+    
+  Int_t *oneSclP = new Int_t[fNClusterP]; //I want to have sorted 1 S clusters
+  Int_t *oneSclN = new Int_t[fNClusterN]; //I can not sort it in TClonesArray
+                                          //so, I create table of indexes and 
+                                          //sort it
+                                          //I do not use TArrayI on purpose
+                                          // MB: well, that's not true that one
+                                          //cannot sort objects in TClonesArray
+  
+  Int_t i,k;    //iterator
+  AliITSpackageSSD *currentpkg;
+  AliITSclusterSSD *currentP;
+  AliITSclusterSSD *currentN;
+  AliITSclusterSSD *fcurrN;
+
+  Int_t     lastNclIndex=0;          //index of last N sidecluster
+  Int_t     Nclpack=0;               //number of P clusters in current package
+  Int_t     Pclpack=0;               //number of N clusters in current package
+  Int_t     firstStripP;
+  Int_t     lastStripP;
+  Int_t     firstStripN;
+  Int_t     lastStripN;
+  Int_t     tmplastNclIndex;
+
+//Fills in One Side Clusters Index Array
+  FillClIndexArrays(oneSclP,oneSclN); 
+//Sorts filled Arrays
+  SortClusters(oneSclP,oneSclN);                   
+
+
+  fNPackages=1;      
+  new ((*fPackages)[0]) AliITSpackageSSD(fClusterP,fClusterN);
+  currentpkg = (AliITSpackageSSD*)((*fPackages)[0]);
+  
+  //main loop on sorted P side clusters 
+  for(i=0;i<fNClusterP;i++) {  
+      //Take new P side cluster
+      currentP = GetPSideCluster(oneSclP[i]);
+      currentN = GetNSideCluster(oneSclN[lastNclIndex]);
+      // take a new P cluster or not ?
+      if(IsCrossing(currentP,currentN)) {
+         // don't take a new P cluster
+          Pclpack++;
+          currentP->AddCross(oneSclN[lastNclIndex]);
+          currentN->AddCross(oneSclP[i]);
+          currentpkg->AddPSideCluster(oneSclP[i]);
+          if (Nclpack==0) {
+              currentpkg->AddNSideCluster(oneSclN[lastNclIndex]);          
+              Nclpack++;
+         }  
+         //check if previous N side clusters crosses with it too    
+          for(k=1;k<fSFB+1;k++) {
+             //check if we are not out of array 
+              if ((lastNclIndex-k)>-1) {
+                  fcurrN = GetNSideCluster( oneSclN[lastNclIndex-k] );
+                  if( IsCrossing(currentP,fcurrN) ) {
+                     currentP->AddCross(oneSclN[lastNclIndex-k]);
+                      fcurrN->AddCross(oneSclP[i]);      
+                } else break; //There is no sense to check rest of clusters
+             } else break;
+         }
+          tmplastNclIndex=lastNclIndex;  
+         //Check if next N side clusters crosses with it too
+          for(k=1;k<fSFF+1;k++) {
+             //check if we are not out of array 
+              if ((tmplastNclIndex+k)<fNClusterN) {
+                  fcurrN = GetNSideCluster( oneSclN[tmplastNclIndex+k] );
+                  if(IsCrossing(currentP,fcurrN) ) {
+                     lastNclIndex++;
+                     fcurrN->AddCross(oneSclP[i]);
+                     currentP->AddCross(oneSclN[tmplastNclIndex+k]);
+                     currentpkg->AddNSideCluster(oneSclN[lastNclIndex]);
+                     Nclpack++;
+                 }else break;
+             } else break;
+         }
+      
+         // end of package 
+         //if( IsCrossing )
+      } else { 
+         lastStripP  = currentP->GetLastDigitStripNo();
+         lastStripN  = currentN->GetLastDigitStripNo();
+         
+         if((lastStripN-fSFF) < lastStripP ) {
+           //Take new PCluster
+            if((Nclpack>0)&& (Pclpack>0)) {
+              new ((*fPackages)[fNPackages]) AliITSpackageSSD(fClusterP,fClusterN);
+              currentpkg = (AliITSpackageSSD*)((*fPackages)[fNPackages++]);
+           }
+              
+           //so we have to take another cluster on side N and check it
+           //we have to check until taken cluster's last strip will 
+           //be > last of this cluster(P)
+           //so it means that there is no corresponding cluster on side N 
+           //to this cluster (P)
+           //so we have to continue main loop with new "lastNclIndex"
+         
+           Nclpack=0;     
+           Pclpack=0;   
+           //We are not sure that next N cluter will cross with this P cluster
+           //There might one, or more, clusters that do not have any 
+           //corresponding cluster on the other side      
+           for(;;) {     
+              lastNclIndex++;
+              //Check if we are not out of array
+              if (lastNclIndex<fNClusterN) {
+                 currentN = GetNSideCluster(oneSclN[lastNclIndex]);
+                 if ( IsCrossing(currentP, currentN) ){
+                    Nclpack++;       
+                    Pclpack++;
+                    currentP->AddCross(oneSclN[lastNclIndex]);
+                    currentN->AddCross(oneSclP[i]);
+                    currentpkg->AddNSideCluster(oneSclN[lastNclIndex]);
+                    currentpkg->AddPSideCluster(oneSclP[i]);          
+                    //Check, if next N side clusters crosses with it too
+                    tmplastNclIndex=lastNclIndex;
+                    for(k=1;k<fSFF+1;k++) {
+                      //Check if we are not out of array
+                      if ((tmplastNclIndex+k)<fNClusterN) {
+                         fcurrN = GetNSideCluster(oneSclN[tmplastNclIndex+k]);
+                         if( IsCrossing(currentP, fcurrN) ) {
+                            Nclpack++;
+                            lastNclIndex++;
+                            currentP->AddCross(oneSclN[tmplastNclIndex+k]);
+                            fcurrN->AddCross(oneSclP[i]);
+                            currentpkg->AddNSideCluster(oneSclN[tmplastNclIndex+k]);
+                         }else break;
+                      } else break; //we are out of array
+                    } // end loop 
+                    break;
+                 } else {
+                    firstStripP = currentP->GetFirstDigitStripNo();
+                    firstStripN = currentN->GetFirstDigitStripNo();
+                    if((firstStripN+fSFB)>=firstStripP) break;
+                    else continue;
+                 }  
+              } else goto EndOfFunction;
+           } // end for(;;)
+        }  else  //EndOfPackage
+          {
+            continue;     
+          } //else EndOfPackage
+       
+      }//else IsCrossing
+           
+  }//main for
+
+ EndOfFunction:
+  if ((Nclpack<1) || (Pclpack<1)) fNPackages--;
+
+   delete oneSclP;
+   delete oneSclN;
+
+}
+
+
+
+//-----------------------------------------------
+void AliITSClusterFinderSSD::PackagesToPoints()
+{
+ register Int_t i;
+ AliITSpackageSSD *currentpkg;
+ Int_t NumNcl;
+ Int_t NumPcl;
+ Int_t clusterIndex;
+ Bool_t clusterSide;
+
+ for(i=0;i<fNPackages;i++) {
+    //get pointer to next package
+    currentpkg = (AliITSpackageSSD*)((*fPackages)[i]); 
+    NumNcl = currentpkg->GetNumOfClustersN();
+    NumPcl = currentpkg->GetNumOfClustersP();
+    if(debug) cout<<"New Package\nNumPcl ="<<NumPcl<<" NumNcl ="<<NumNcl<<"\n";
+
+    while(((NumPcl>=2)&&(NumNcl>2))||((NumPcl>2)&&(NumNcl>=2))) {  
+        //This is case of "big" pacakage
+        //conditions see 3 lines above  
+        //if in the big package exists cluster with one cross 
+       //we can reconstruct this point without any geometrical ambiguities
+       if(currentpkg->GetClusterWithOneCross(clusterIndex, clusterSide) )
+        {
+            ResolveClusterWithOneCross(currentpkg, clusterIndex, clusterSide);
+        } else if (clusterIndex == -2) {
+           NumPcl = 0;
+           NumNcl = 0;
+           break;
+        } else {
+           if ( (NumNcl==NumPcl) && (NumPcl<10)) {
+               //if there is no cluster with one cross 
+              //we can resolve whole package at once 
+              //by finding best combination
+              //we can make combinations when NumNcl==NumPcl
+              if (ResolvePackageBestCombin(currentpkg)) { 
+                   //sometimes creating combinations fail, 
+                  //but it happens very rarely
+                  NumPcl = 0;
+                  NumNcl = 0;
+                  break;
+              } else ResolveOneBestMatchingPoint(currentpkg);
+           } else {
+              ResolveOneBestMatchingPoint(currentpkg);
+           }
+        }
+       NumNcl = currentpkg->GetNumOfClustersN();
+       NumPcl = currentpkg->GetNumOfClustersP();
+    } // end while 
+    if ((NumPcl==1)&&(NumNcl==1)) {
+      ResolveSimplePackage(currentpkg);
+       continue;
+    }
+    if (NumPcl==1) {
+      ResolvePackageWithOnePSideCluster(currentpkg);
+      continue;
+    }
+    if (NumNcl==1) {
+      ResolvePackageWithOneNSideCluster(currentpkg);
+      continue;
+    }
+    if ((NumPcl==2)&&(NumNcl==2)) {
+      ResolveTwoForTwoPackage(currentpkg);
+      continue; 
+    }
+    if ((NumPcl==0)&&(NumNcl>0)) { }
+    if ((NumNcl==0)&&(NumPcl>0)) { }
+
+  } // end loop over fNPackages
+
+
+}
+
+
+//----------------------------------------------------------
+
+void AliITSClusterFinderSSD::
+ResolveClusterWithOneCross(AliITSpackageSSD *currentpkg, Int_t clusterIndex, Bool_t clSide)
+{
+
+   if (clSide == SIDEP) ResolvePClusterWithOneCross(currentpkg,clusterIndex);
+   else  ResolveNClusterWithOneCross(currentpkg,clusterIndex);
+
+}
+
+
+//---------------------------------------------------------
+void AliITSClusterFinderSSD::
+ResolvePClusterWithOneCross(AliITSpackageSSD *pkg, Int_t clusterIndex)
+{
+
+/*
+There is cluster (side P) which crosses with only one cluster on the other 
+side (N)
+
+ie:
+    \    /  \/   /
+     \  /   /\  /
+      \/   /  \/
+      /\  /   /\
+     /  \/   /  \    .....
+    /   /\  /    \
+   /   /  \/      \
+  /   /   /\       \
+ /   /   /  \       \
+*/
+
+
+  AliITSclusterSSD * clusterP;
+  AliITSclusterSSD * clusterN;
+
+  Float_t posClusterP;           //Cluster P position in strip coordinates
+  Float_t posClusterN;           //Cluster N position in strip coordinates
+  
+  Float_t posErrorClusterP;
+  Float_t posErrorClusterN;
+  
+  Float_t sigClusterP;
+  Float_t sigClusterN;
+
+  Float_t sigErrorClusterP;
+  Float_t sigErrorClusterN;
+
+  Float_t ps;
+  Float_t ns;
+  
+  Float_t Chicomb;
+  Int_t clusterIdx;
+
+  if (debug) cout<<"ResolvePClusterWithOneCross\n";
+
+  clusterP=pkg->GetPSideCluster(clusterIndex);
+  posClusterP = GetClusterZ(clusterP);
+  posErrorClusterP = clusterP->GetPositionError();
+  sigClusterP = ps = clusterP->GetTotalSignal();
+  sigErrorClusterP = clusterP->GetTotalSignalError(); 
+  //carefully, it returns index in TClonesArray
+  
+  clusterIdx = clusterP->GetCross(0);
+  clusterN=this->GetNSideCluster(clusterIdx);
+  ns = clusterN->GetTotalSignal();
+  posClusterN = GetClusterZ(clusterN);
+  posErrorClusterN = clusterN->GetPositionError();
+  pkg->DelCluster(clusterIndex,SIDEP);
+  sigClusterN = ps/PNsignalRatio;
+  // there is no sonse to check how signal ratio is far from perfect 
+  // matching line if the if below it is true
+  if (ns < sigClusterN) {
+      sigClusterN=ns;
+      if (debug) cout<<"n1 < p1/PNsignalRatio";
+      if (debug) cout<<"Attempting to del cluster N "<<clusterIdx<<" ... \n";
+      pkg->DelClusterOI(clusterIdx,SIDEN);
+  } else {
+      //Let's see how signal ratio is far from perfect matching line
+      Chicomb = DistToPML(ps,ns);
+      if (debug) cout<<"Chic "<<Chicomb<<"\n";
+      if (Chicomb > falpha2) {
+         //it is near, so we can risk throwing this cluster away too
+        if (debug) cout<<"Attempting to del cluster N "<<clusterIdx<<"...\n"; 
+         pkg->DelClusterOI(clusterIdx,SIDEN);
+      } else {
+         clusterN->CutTotalSignal(sigClusterN);
+        if (debug) cout <<"Signal cut  |||||||||||||\n";
+      }
+  }
+  sigErrorClusterN= clusterN->GetTotalSignalError(); 
+  CreateNewRecPoint(posClusterP,posErrorClusterP,posClusterN,posErrorClusterN,
+                    sigClusterP+sigClusterN, sigErrorClusterN+sigErrorClusterP,
+                   clusterP, clusterN, 0.75);
+
+}
+
+
+//------------------------------------------------------
+void AliITSClusterFinderSSD::
+ResolveNClusterWithOneCross(AliITSpackageSSD *pkg, Int_t clusterIndex)
+{
+
+  AliITSclusterSSD * clusterP;
+  AliITSclusterSSD * clusterN;
+
+  Float_t posClusterP;              //Cluster P position in strip coordinates
+  Float_t posClusterN;              //Cluster N position in strip coordinates
+
+  Float_t posErrorClusterP;
+  Float_t posErrorClusterN;
+
+  Float_t sigClusterP;
+  Float_t sigClusterN;
+
+  Float_t sigErrorClusterP;
+  Float_t sigErrorClusterN;
+
+  Float_t ps;
+  Float_t ns;
+  
+  Float_t Chicomb;
+  Int_t clusterIdx;
+  
+  if (debug) cout<<"ResolveNClusterWithOneCross\n"; 
+  
+  clusterN=pkg->GetNSideCluster(clusterIndex);
+  posClusterN = GetClusterZ(clusterN);
+  posErrorClusterN = clusterN->GetPositionError();
+  sigClusterN = ns = clusterN->GetTotalSignal();
+  sigErrorClusterN = clusterN->GetTotalSignalError(); 
+  //carefully, it returns index in TClonesArray
+  clusterIdx = clusterN->GetCross(0);
+  clusterP=this->GetPSideCluster(clusterIdx);
+  ps = clusterP->GetTotalSignal();
+  posClusterP = GetClusterZ(clusterP);
+  posErrorClusterP = clusterP->GetPositionError();
+  pkg->DelCluster(clusterIndex,SIDEN);
+  sigClusterP=ns*PNsignalRatio;
+  // there is no sonse to check how signal ratio is far from perfect 
+  // matching line if the if below it is true
+  if (ps < sigClusterP) {
+      sigClusterP = ps;
+      if (debug) cout<<"ps < ns*PNsignalRatio";
+      if (debug) cout<<"Attempting to del cluster P "<<clusterIdx<<" ... \n";
+      pkg->DelClusterOI(clusterIdx,SIDEP);
+  } else {
+      //Let's see how signal ratio is far from perfect matching line
+       Chicomb = DistToPML(ps,ns);
+       if (debug) cout<<"Chic "<<Chicomb<<"\n";
+       if (Chicomb > falpha2) {
+          //it is near, so we can risk frowing this cluster away too
+          if (debug) cout<<"Attempting to del cluster P "<<clusterIdx<<"...\n";
+         pkg->DelClusterOI(clusterIdx,SIDEP);
+       } else {
+          clusterN->CutTotalSignal(sigClusterP);
+         if (debug) cout <<"Signal cut  ------------\n";
+       }
+  }
+  sigErrorClusterP= clusterP->GetTotalSignalError(); 
+  CreateNewRecPoint( posClusterP,posErrorClusterP,posClusterN,posErrorClusterN,
+                     sigClusterP+sigClusterN,sigErrorClusterN+sigErrorClusterP,
+                    clusterP, clusterN, 0.75);
+
+
+}
+
+
+
+//-------------------------------------------------------
+
+Bool_t AliITSClusterFinderSSD::
+ResolvePackageBestCombin(AliITSpackageSSD *pkg)
+{
+  if (debug) cout<<"NumNcl==NumPcl ("<<pkg->GetNumOfClustersN()
+      <<"=="<<pkg->GetNumOfClustersP()<<"); Generating combinations ... \n";
+
+
+  AliITSclusterSSD * clusterP;
+  AliITSclusterSSD * clusterN;
+
+  Int_t Ncombin; //Number of combinations
+  Int_t itera;   //iterator
+  Int_t sizet=1;   //size of array to allocate 
+  Int_t NP = pkg->GetNumOfClustersP();
+  for(itera =2; itera <= NP ;itera ++) {
+     sizet=sizet*itera;
+     if (sizet > 10000) {
+       sizet=10000;
+       break;
+     }
+  }
+
+  Int_t** combin = new (Int_t*)[sizet]; //2D array to keep combinations in
+
+  for(itera =0; itera <sizet;itera++) {
+   combin[itera] = new Int_t[NP+1];
+  }
+     
+  pkg->GetAllCombinations(combin,Ncombin,sizet);
+  if (Ncombin==0) { 
+    if (debug) cout<<"No combin Error";
+    return kFALSE;
+  }
+//calculate which combination fits the best to perfect matching line 
+  Int_t bc = GetBestComb(combin,Ncombin,NP,pkg); 
+  if (debug) cout<<"  bc "<<bc <<"\n";
+              
+  for(itera =0; itera < NP; itera ++) {
+      clusterP = pkg->GetPSideCluster(itera);
+      //carefully here
+      //becase AliITSclusterSSD::GetCross returns index in 
+      //AliITSmoduleSSD.fClusterP, which is put to "combin"        
+      clusterN = GetNSideCluster(combin[bc][itera]);
+      CreateNewRecPoint(clusterP, clusterN, 0.75);
+  } 
+
+  for(itera =0; itera <sizet;itera++) {
+     delete [](combin[itera]);
+  }
+  delete [] combin;  
+  return kTRUE;
+
+}
+
+
+//----------------------------------------------------
+void AliITSClusterFinderSSD::
+ResolveOneBestMatchingPoint(AliITSpackageSSD *pkg)
+{
+
+ Int_t ni, pi;
+
+ Int_t prvP, prvN;
+ Int_t nextP, nextN=0;
+
+  
+ AliITSclusterSSD * clusterP;
+ AliITSclusterSSD * clusterN;
+
+ Bool_t split = kFALSE;
+
+ if (debug) cout<<"ResolveOneBestMatchingPoint \n";
+
+ GetBestMatchingPoint(pi, ni, pkg);
+         
+ clusterP = GetPSideCluster(pi);
+ clusterN = GetNSideCluster(ni);
+              
+ CreateNewRecPoint(clusterP, clusterN, 0.75);
+ if ((nextP=pkg->GetNextPIdx(pi))!=-1)
+   if ((nextN=pkg->GetNextNIdx(ni))!=-1)
+     if ((prvP=pkg->GetPrvPIdx(pi))!=-1)
+       if ((prvN=pkg->GetPrvNIdx(ni))!=-1)
+          if( !(GetPSideCluster(prvP)->IsCrossingWith(nextN)))
+            if( !(GetPSideCluster(nextP)->IsCrossingWith(prvN)))
+              {
+                 split = kTRUE;
+              }          
+ pkg->DelClusterOI(pi, SIDEP);
+ pkg->DelClusterOI(ni, SIDEN);
+ if (split) {
+   if (debug) cout<<"spltting package ...\n";
+   new ((*fPackages)[fNPackages]) AliITSpackageSSD(fClusterP,fClusterN);
+   pkg->
+     SplitPackage(nextP,nextN,(AliITSpackageSSD*)((*fPackages)[fNPackages++]));
+ }
+
+}
+
+
+//--------------------------------------------------
+void  AliITSClusterFinderSSD::ResolveSimplePackage(AliITSpackageSSD *pkg)
+{
+
+  AliITSclusterSSD * clusterP;
+  AliITSclusterSSD * clusterN;
+
+  clusterP         = pkg->GetPSideCluster(0);
+        
+  clusterN         = pkg->GetNSideCluster(0);
+
+  CreateNewRecPoint(clusterP, clusterN, 1.0);
+
+
+} 
+
+
+//--------------------------------------------------
+void AliITSClusterFinderSSD:: ResolvePackageWithOnePSideCluster(AliITSpackageSSD *pkg) {
+
+
+/*
+ \   \   \  /
+  \   \   \/
+   \   \  /\
+    \   \/  \
+     \  /\   \
+      \/  \   \
+      /\   \   \
+     /  \   \   \  
+
+*/
+
+
+/************************/
+/**************************/
+/*XP SP itg jest tylko jeden nie musi byc tablica i w peetli nie trzeba po niej iterowcac*/
+/***************************/
+
+
+ Int_t k;
+ AliITSclusterSSD * clusterP;
+ AliITSclusterSSD * clusterN;
+ Int_t NN=pkg->GetNumOfClustersN();
+ Float_t sumsig = 0;
+ Float_t   XP;
+ Float_t   XPerr;
+ Float_t * XN = new Float_t[NN];
+ Float_t * XNerr = new Float_t[NN];
+ Float_t * SP = new Float_t[NN];
+ Float_t * SN = new Float_t[NN];
+ Float_t * SPerr = new Float_t[NN];
+ Float_t * SNerr = new Float_t[NN];
+ Float_t p1;
+ Float_t p1err;
+ clusterP = pkg->GetPSideCluster(0);
+ p1       = clusterP->GetTotalSignal();
+   
+ XP    = GetClusterZ(clusterP);
+ XPerr = clusterP->GetPositionError();
+ p1err = clusterP->GetTotalSignalError();
+   
+ for(k=0;k<NN;k++) {
+    SN[k]    = pkg->GetNSideCluster(k)->GetTotalSignal();
+    SNerr[k] = pkg->GetNSideCluster(k)->GetTotalSignalError();
+    sumsig   += SN[k];
+ }
+ for(k=0;k<NN;k++) {
+    clusterN = pkg->GetNSideCluster(k);
+    SP[k]= p1*SN[k]/sumsig;
+    SPerr[k] = p1err*SN[k]/sumsig;
+    XN[k]=GetClusterZ(clusterN);
+    XNerr[k]= clusterN->GetPositionError();
+    CreateNewRecPoint(XP,XPerr, XN[k],XNerr[k], SP[k]+SN[k], SPerr[k]+SNerr[k], clusterP, clusterN, 1.0);
+
+ }
+
+}
+
+
+//---------------------------------------------------------
+void AliITSClusterFinderSSD::ResolvePackageWithOneNSideCluster(AliITSpackageSSD *pkg) {
+
+
+/*
+    \    /   /   /
+     \  /   /   /
+      \/   /   /
+      /\  /   /
+     /  \/   /
+    /   /\  /  
+   /   /  \/
+  /   /   /\
+ /   /   /  \  
+*/
+
+
+ Int_t k;
+ AliITSclusterSSD * clusterP;
+ AliITSclusterSSD * clusterN;
+ Int_t NP=pkg->GetNumOfClustersP();
+ Float_t sumsig = 0;
+ Float_t * XP = new Float_t[NP];
+ Float_t * XPerr = new Float_t[NP];
+ Float_t   XN;
+ Float_t   XNerr;
+ Float_t * SP = new Float_t[NP];
+ Float_t * SN = new Float_t[NP];
+ Float_t * SPerr = new Float_t[NP];
+ Float_t * SNerr = new Float_t[NP];
+ Float_t n1;
+ Float_t n1err;
+
+ clusterN = pkg->GetNSideCluster(0);
+ n1       = clusterN->GetTotalSignal();
+   
+ XN = GetClusterZ(clusterN);
+ XNerr = clusterN->GetPositionError();
+ n1err=clusterN->GetTotalSignalError();
+   
+ for(k=0;k<NP;k++) {
+    SP[k] = pkg->GetPSideCluster(k)->GetTotalSignal();
+    sumsig += SP[k];
+    SPerr[k] = pkg->GetPSideCluster(k)->GetTotalSignalError();
+ }
+
+ for(k=0;k<NP;k++) {
+    clusterP = pkg->GetPSideCluster(k);
+    SN[k]= n1*SP[k]/sumsig;
+    XP[k]=GetClusterZ(clusterP);
+    XPerr[k]= clusterP->GetPositionError();
+    SNerr[k] = n1err*SP[k]/sumsig;
+    CreateNewRecPoint(XP[k],XPerr[k], XN,XNerr, SP[k]+SN[k], SPerr[k]+SNerr[k],clusterP, clusterN, 1.0);
+  }
+  
+               
+}
+
+/**********************************************************************/
+/*********      2  X   2  *********************************************/
+/**********************************************************************/
+
+void AliITSClusterFinderSSD::
+ResolveTwoForTwoPackage(AliITSpackageSSD *pkg)
+{
+
+  AliITSclusterSSD *clusterP1 = pkg->GetPSideCluster(0);
+  AliITSclusterSSD *clusterP2 = pkg->GetPSideCluster(1);
+  AliITSclusterSSD *clusterN1 = pkg->GetNSideCluster(0);
+  AliITSclusterSSD *clusterN2 = pkg->GetNSideCluster(1);
+
+  AliITSclusterSSD *tmp;
+
+  Float_t p1sig;
+  Float_t p2sig;
+  Float_t n1sig;
+  Float_t n2sig;
+
+  Float_t p1sigErr;
+  Float_t p2sigErr;
+  Float_t n1sigErr;
+  Float_t n2sigErr;
+
+  Float_t ZposP1;
+  Float_t ZposP2;
+  Float_t ZposN1;
+  Float_t ZposN2;
+
+  Float_t ZposErrP1;
+  Float_t ZposErrP2;
+  Float_t ZposErrN1;
+  Float_t ZposErrN2;
+
+  Float_t D12;
+
+  Float_t Chicomb1;
+  Float_t Chicomb2;
+
+  if(clusterP1->GetDigitStripNo(0) > clusterP2->GetDigitStripNo(0)) {
+     if (debug) cout<<"P strips flip\n";
+     tmp       = clusterP1;
+     clusterP1 = clusterP2;
+     clusterP2 = tmp;
+  }
+  if(clusterN1->GetDigitStripNo(0) > clusterN2->GetDigitStripNo(0)) {
+     if (debug) cout<<"N strips flip\n";
+     tmp       = clusterN1;
+     clusterN1 = clusterN2;
+     clusterN2 = tmp;
+  }
+  p1sig = clusterP1->GetTotalSignal();
+  p2sig = clusterP2->GetTotalSignal();
+  n1sig = clusterN1->GetTotalSignal();
+  n2sig = clusterN2->GetTotalSignal();
+
+
+  p1sigErr = clusterP1->GetTotalSignalError();
+  n1sigErr = clusterN1->GetTotalSignalError();
+  p2sigErr = clusterP2->GetTotalSignalError();
+  n2sigErr = clusterN2->GetTotalSignalError();
+          
+  ZposP1 = clusterP1->GetPosition();
+  ZposN1 = clusterN1->GetPosition();
+  ZposP2 = clusterP2->GetPosition();
+  ZposN2 = clusterN2->GetPosition();
+
+  ZposErrP1 = clusterP1->GetPositionError();
+  ZposErrN1 = clusterN1->GetPositionError();
+  ZposErrP2 = clusterP2->GetPositionError();
+  ZposErrN2 = clusterN2->GetPositionError();
+
+  //in this may be two types:
+  //    1.When each cluster crosses with 2 clusters on the other side
+  //            gives 2 ghosts and 2 real points
+  //
+  //    2.When two clusters (one an each side) crosses with only one on 
+  //           the other side and two crosses (one on the each side) with 
+  //           two on the other gives 2 or 3 points,
+   
+  if (debug) cout<<"2 for 2 ambiguity ...";
+  /***************************/
+  /*First sort of combination*/
+  /***************************/
+  
+  if((clusterP1->GetCrossNo()==2) && (clusterN1->GetCrossNo()==2)) {  
+     if (debug) cout<<"All clusters has 2 crosses\n";
+     D12 = TMath::Sqrt((Float_t)((p1sig -p2sig)*(p1sig -p2sig) + (n1sig -n2sig)*(n1sig -n2sig)));
+           
+     if(debug) cout<<"Distance between points in P(N) plane D12 = "<<D12<<"\n";
+            
+     /*********************************************/
+     /*resolving ambiguities:                     */
+     /*we count Chicomb's and we take combination */
+     /*giving lower Chicomb as a real points      */
+     /*Keep only better combinantion              */
+     /*********************************************/
+           
+     if (D12 > (falpha3*17.8768)) {
+       if (debug) cout<<"decided to take only one pair \n";
+       Chicomb1 = DistToPML(p1sig,n1sig) + DistToPML(p2sig,n2sig);
+       Chicomb2 = DistToPML(p2sig,n1sig) + DistToPML(p1sig,n2sig);
+       if (debug) {
+        cout<<" 00 11 combination : "<<Chicomb1<<" 01 10 combination : "<<Chicomb2<<" \n";
+        cout<<"p1 = "<<p1sig<<"  n1 = "<<n1sig<<"  p2 = "<<p2sig<<"  n2 = "<<n2sig<<"\n"; 
+       }
+       if (Chicomb1 < Chicomb2) {
+         if (debug) cout<<"00 11";
+         CreateNewRecPoint(ZposP1,ZposErrP1, ZposN1,ZposErrN1, p1sig+n1sig, p1sigErr+n1sigErr, clusterP1, clusterN1, 0.75);   
+         CreateNewRecPoint(ZposP2,ZposErrP2, ZposN2,ZposErrN2, p2sig+n2sig, p2sigErr+n2sigErr, clusterP2, clusterN2, 0.75); 
+
+  
+         //second cominantion
+       } else {
+         if (debug) cout<<"01 10";
+         CreateNewRecPoint(ZposP1,0, ZposN2,0, p1sig+n2sig, p1sigErr+n2sigErr, clusterP1, clusterN2, 0.75);   
+         CreateNewRecPoint(ZposP2,0, ZposN1,0, p2sig+n1sig, p2sigErr+n1sigErr, clusterP2, clusterN1, 0.75);    
+       } //end second combinantion
+       //if (D12 > falpha3*17.8768)
+       //keep all combinations
+     } else {
+        if (debug) cout<<"We decide to take all points\n";
+       CreateNewRecPoint(ZposP1,ZposErrP1, ZposN1,ZposErrN1, p1sig+n1sig, p1sigErr+n1sigErr, clusterP1, clusterN1, 0.5);   
+       CreateNewRecPoint(ZposP2,ZposErrP2, ZposN2,ZposErrN2, p2sig+n2sig, p2sigErr+n2sigErr, clusterP2, clusterN2, 0.5);   
+       CreateNewRecPoint(ZposP1,ZposErrP1, ZposN2,ZposErrN2, p1sig+n2sig, p1sigErr+n2sigErr, clusterP1, clusterN2, 0.5);   
+       CreateNewRecPoint(ZposP2,ZposErrP2, ZposN1,ZposErrN1, p2sig+n1sig, p2sigErr+n1sigErr, clusterP2, clusterN1, 0.5);    
+     }
+  }
+  // ad.2 Second type of combination
+  else {
+    Chicomb1 = DistToPML(p1sig,n1sig) + DistToPML(p2sig,n2sig);
+    if (debug) cout<<"\nhere can be reconstructed 3 points: chicomb = "<<Chicomb1<<"\n"; 
+  
+    if (Chicomb1<falpha1) {
+       if (debug) cout<<"\nWe decided to take 3rd point"; 
+       if (clusterP1->GetCrossNo()==1) {
+         if (debug) cout<<"...  P1 has one cross\n"; 
+         n1sig = p1sig/PNsignalRatio;
+         p2sig = n2sig*PNsignalRatio;
+              
+         clusterN1->CutTotalSignal(n1sig);
+         clusterP2->CutTotalSignal(p2sig);
+       
+         CreateNewRecPoint(ZposP2,ZposErrP2, ZposN1,ZposErrN1, p2sig+n1sig, p2sigErr+n1sigErr, clusterP2, clusterN1, 0.5);    
+
+         n1sig = clusterN1->GetTotalSignal();
+         p2sig = clusterP2->GetTotalSignal();
+
+       } else {
+         if (debug) cout<<"...  N1 has one cross\n";
+             
+         n2sig=p2sig/PNsignalRatio;
+         p1sig=n1sig*PNsignalRatio;
+
+         clusterN2->CutTotalSignal(n2sig);
+         clusterP1->CutTotalSignal(p1sig);
+
+         CreateNewRecPoint(ZposP1,ZposErrP1, ZposN2,ZposErrN2, p1sig+n2sig, p1sigErr+n2sigErr, clusterP1, clusterN2, 0.5);   
+         
+         n2sig=clusterN2->GetTotalSignal();
+         p1sig=clusterP1->GetTotalSignal();
+       }
+    } else {
+       if (debug) cout<<"\nWe decided  NOT to take 3rd point\n"; 
+    }
+
+    CreateNewRecPoint(ZposP1,ZposErrP1, ZposN1,ZposErrN1, p1sig+n1sig, p1sigErr+n1sigErr, clusterP1, clusterN1, 1.0);   
+    CreateNewRecPoint(ZposP2,ZposErrP2, ZposN2,ZposErrN2, p2sig+n2sig, p2sigErr+n2sigErr, clusterP2, clusterN2, 1.0);   
+  
+  }
+
+}
+
+
+
+//------------------------------------------------------
+Bool_t AliITSClusterFinderSSD::    
+CreateNewRecPoint(Float_t P, Float_t dP, Float_t N, Float_t dN,
+                  Float_t Sig,Float_t dSig, 
+                  AliITSclusterSSD *clusterP, AliITSclusterSSD *clusterN,
+                  Stat_t prob)
+{
+
+  const Float_t kdEdXtoQ = 2.778e+8;
+  const Float_t kconv = 1.0e-4; 
+  const Float_t kRMSx = 20.0*kconv; // microns->cm ITS TDR Table 1.3
+  const Float_t kRMSz = 830.0*kconv; // microns->cm ITS TDR Table 1.3
+
+
+  Float_t p=P;
+  Float_t n=N;
+  if (GetCrossing(P,N)) {
+     GetCrossingError(dP,dN);
+     AliITSRawClusterSSD cnew;
+     Int_t nstripsP=clusterP->GetNumOfDigits();
+     Int_t nstripsN=clusterN->GetNumOfDigits();
+     cnew.fMultiplicity=nstripsP;
+     cnew.fMultiplicityN=nstripsN;
+     /*
+     if (nstripsP > 100) {
+        printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsP);
+        nstripsP=100;
+     }
+     Int_t i;
+     for(i=0;i<nstripsP;i++) {
+       // check if 'clusterP->GetDigitStripNo(i)' returns the digit index
+       cnew.fIndexMap[i] = clusterP->GetDigitStripNo(i); 
+     } 
+     if (nstripsN > 100) {
+        printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsN);
+        nstripsN=100;
+     }
+     for(i=0;i<nstripsN;i++) {
+       // check if 'clusterN->GetDigitStripNo(i)' returns the digit index
+       cnew.fIndexMapN[i] = clusterN->GetDigitStripNo(i); 
+     }
+     */
+     cnew.fQErr=dSig;
+     //cnew.fProbability=(float)prob; 
+     fITS->AddCluster(2,&cnew);
+     // add the rec point info
+     AliITSRecPoint rnew;
+     rnew.SetX(P*kconv);
+     rnew.SetZ(N*kconv);
+     rnew.SetQ(Sig);
+     rnew.SetdEdX(Sig/kdEdXtoQ);
+     rnew.SetSigmaX2( kRMSx* kRMSx); 
+     rnew.SetSigmaZ2( kRMSz* kRMSz);
+     rnew.SetProbability((float)prob);
+     fITS->AddRecPoint(rnew);
+     /*
+     // it was
+     fPointsM->AddLast( (TObject*) 
+                   new AliITSRecPointSSD(P,dP,0,0,N,dN,Sig,dSig,fLayer,fLad,fDet,clusterP,clusterN,prob) );
+     */
+    
+     if(debug) cout<<"\n"<<": ImpactPoint Created: X = "<<P<<" Z = "<<N<<";   P = "<<p<<"  N = "<<n<<"\n";
+     return kTRUE;
+  } else { 
+     if (debug) {
+       cout<<"\n"<<": ATENTION : stupid ImpactPoit Point X = "<<P<<" Z = "<<N<<";  P = "<<p<<"  N = "<<n<<"\n";
+     }
+     return kFALSE;
+  }
+}
+
+
+
+/**********************************************************************/
+Bool_t  AliITSClusterFinderSSD::
+CreateNewRecPoint(AliITSclusterSSD *clusterP, AliITSclusterSSD *clusterN, Stat_t prob)
+{
+  Float_t posClusterP;  //Cluster P position in strip coordinates
+  Float_t posClusterN;  //Cluster N position in strip coordinates
+  Float_t posErrorClusterP;
+  Float_t posErrorClusterN;
+
+  Float_t sigClusterP;
+  Float_t sigClusterN;
+
+  Float_t sigErrorClusterP;
+  Float_t sigErrorClusterN;
+
+  posClusterP      = clusterP->GetPosition();
+  posErrorClusterP = clusterP->GetPositionError();
+  sigClusterP      = clusterP->GetTotalSignal();
+  sigErrorClusterP = clusterP->GetTotalSignalError();
+
+  posClusterN      = clusterN->GetPosition();
+  posErrorClusterN = clusterN->GetPositionError();
+  sigClusterN      = clusterN->GetTotalSignal();
+  sigErrorClusterN = clusterN->GetTotalSignalError();
+
+  return CreateNewRecPoint( posClusterP,posErrorClusterP,  posClusterN,posErrorClusterN, 
+                     sigClusterP+sigClusterN, sigErrorClusterN+sigErrorClusterP,
+                    clusterP, clusterN, prob);
+
+}
+
+//--------------------------------------------------
+Bool_t AliITSClusterFinderSSD::IsCrossing(AliITSclusterSSD* p, AliITSclusterSSD* n)
+{
+  Float_t x = p->GetPosition();
+  Float_t y = n->GetPosition();
+  return GetCrossing(x,y);
+}
+
+
+//----------------------------------------------
+Bool_t AliITSClusterFinderSSD::Strip2Local( Float_t stripP, Float_t stripN, Float_t &Z,Float_t &X)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+/*
+ Z = (stripN-stripP)*fFactorOne;  
+ X = (stripN + stripP - fStripZeroOffset)*fFactorTwo;
+*/
+
+ Float_t P =stripP;
+ Float_t N =stripN;
+
+ GetCrossing(P,N);
+ X=P;
+ Z=N;
+ if (debug) cout<<"P="<<stripP<<" N="<<stripN<<"   X = "<<X<<" Z = "<<Z<<"\n";
+ if ((Z<2.1)&&(Z>-2.1)&&(X<3.65)&&(X>-3.65)) return true; 
+    else return false;  
+
+}
+
+
+//-----------------------------------------------------------
+Float_t  AliITSClusterFinderSSD::GetClusterZ(AliITSclusterSSD* clust)
+{
+
+  return clust->GetPosition();
+
+}
+
+//-------------------------------------------------------------
+Int_t AliITSClusterFinderSSD::GetBestComb
+(Int_t** comb,Int_t Ncomb, Int_t Ncl, AliITSpackageSSD * pkg)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+//returns index of best combination in "comb"
+//comb : sets of combinations
+//       in given combination on place "n" is index of 
+//       Nside cluster coresponding to "n" P side cluster
+//
+//Ncomb : number of combinations == number of rows in "comb"
+//
+//Ncl   : number of clusters in each row  == number of columns in "comb"
+//
+//pkg   : package 
+
+
+  Float_t currbval=-1;  //current best value, 
+                        //starting value is set to number negative, 
+                        //to be changed in first loop turn automatically
+      
+  Int_t  curridx=0;     //index of combination giving currently the best chi^2 
+  Float_t chi;
+  Float_t ps, ns;       //signal of P cluster and N cluster
+
+  Int_t i,j;
+  for(i=0;i<Ncomb;i++)
+    {
+      chi=0;
+      
+      for(j=0;j<Ncl;j++)
+      {
+        ps = pkg->GetPSideCluster(j)->GetTotalSignal();  //carrefully here, different functions
+        ns = GetNSideCluster(comb[i][j])->GetTotalSignal(); 
+        chi+=DistToPML(ps,ns);
+      }
+      
+      if (currbval==-1) currbval = chi;
+      if (chi<currbval)
+        {
+          curridx = i;
+          currbval  =chi;
+        }
+    }
+
+
+  return curridx;
+
+}
+
+//--------------------------------------------------
+void AliITSClusterFinderSSD::GetBestMatchingPoint
+(Int_t & ip, Int_t & in, AliITSpackageSSD* pkg )
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+  if (debug) pkg->PrintClusters();
+  Float_t ps, ns;  //signals on side p & n
+  
+  Int_t nc;       // number of crosses in given p side cluster
+  Int_t n,p;
+  AliITSclusterSSD *curPcl, *curNcl;  //current p side cluster
+  Float_t  bestchi, chi;
+  ip=p=pkg->GetPSideClusterIdx(0);
+  in=n=pkg->GetNSideClusterIdx(0);
+       
+  bestchi=DistToPML(  pkg->GetPSideCluster(0)->GetTotalSignal(),
+                  pkg->GetNSideCluster(0)->GetTotalSignal()  );
+  Int_t i,j;
+  for(i = 0; i< pkg->GetNumOfClustersP(); i++)
+    {
+      
+      p =  pkg->GetPSideClusterIdx(i);   
+      curPcl= GetPSideCluster(p);
+      nc=curPcl->GetCrossNo();
+      ps=curPcl->GetTotalSignal();
+      
+      for(j = 0; j< nc; j++)
+        {
+         n=curPcl->GetCross(j);
+         curNcl= GetNSideCluster(n);
+         ns=curNcl->GetTotalSignal();
+         chi = DistToPML(ps, ns);
+    
+         if (chi <= bestchi)
+          {
+            bestchi = chi;
+            in = n;
+            ip = p;
+          }
+        }
+    }
+  
+}
+
+
+//------------------------------------------------------
+void  AliITSClusterFinderSSD::CalcStepFactor(Float_t Psteo, Float_t Nsteo )
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+
+  // 95 is the pitch, 4000 - dimension along z ?
+  /*
+  fSFF = ( (Int_t)  (Psteo*40000/95 ) );// +1;
+  fSFB = ( (Int_t)  (Nsteo*40000/95 ) );// +1;
+  */
+
+
+  Float_t dz=fSegmentation->Dz();
+
+  fSFF = ( (Int_t)  (Psteo*dz/fPitch ) );// +1;
+  fSFB = ( (Int_t)  (Nsteo*dz/fPitch ) );// +1;
+
+}
+
+
+//-----------------------------------------------------------
+AliITSclusterSSD* AliITSClusterFinderSSD::GetPSideCluster(Int_t idx)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+
+
+  if((idx<0)||(idx>=fNClusterP))
+    {
+      printf("AliITSClusterFinderSSD::GetPSideCluster  : index out of range\n");
+      return 0;
+    }
+  else
+    {
+      return (AliITSclusterSSD*)((*fClusterP)[idx]);
+    }
+}
+
+//-------------------------------------------------------
+AliITSclusterSSD* AliITSClusterFinderSSD::GetNSideCluster(Int_t idx)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+  if((idx<0)||(idx>=fNClusterN))
+    {
+      printf("AliITSClusterFinderSSD::GetNSideCluster  : index out of range\n");
+      return 0;
+    }
+  else
+    {
+      return (AliITSclusterSSD*)((*fClusterN)[idx]);
+    }
+}
+
+//--------------------------------------------------------
+AliITSclusterSSD* AliITSClusterFinderSSD::GetCluster(Int_t idx, Bool_t side)
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+
+  return (side) ? GetPSideCluster(idx) : GetNSideCluster(idx);
+}
+
+
+//--------------------------------------------------------
+void AliITSClusterFinderSSD::ConsumeClusters()
+{
+
+ Int_t i;
+ for(i=0;i<fNPackages;i++)
+  {
+    ((AliITSpackageSSD*)((*fPackages)[i]))->ConsumeClusters();
+  }
+
+}
+
+
+//--------------------------------------------------------
+void AliITSClusterFinderSSD::ReconstructNotConsumedClusters()
+{
+  Int_t i;
+  AliITSclusterSSD *cluster;
+  Float_t pos;
+  Float_t sig;
+  Float_t sigerr;
+  Float_t x1,x2,z1,z2;
+
+  Float_t Dx = fSegmentation->Dx();
+  Float_t Dz = fSegmentation->Dz();
+  
+  const Float_t kdEdXtoQ = 2.778e+8; // GeV -> number of e-hole pairs
+  const Float_t kconv = 1.0e-4; 
+  const Float_t kRMSx = 20.0*kconv; // microns->cm ITS TDR Table 1.3
+  const Float_t kRMSz = 830.0*kconv; // microns->cm ITS TDR Table 1.3
+  
+  for(i=0;i<fNClusterP;i++)
+    {
+      //printf("P side cluster: cluster number %d\n",i);
+      cluster = GetPSideCluster(i);
+      if (!cluster->IsConsumed())
+        {
+          if( (pos = cluster->GetPosition()) < fSFB)
+            {
+              sig = cluster->GetTotalSignal();
+              
+              sig += sig/PNsignalRatio;
+              
+              sigerr = cluster->GetTotalSignalError();
+              x1 = -Dx/2 + pos *fPitch;
+              z1 = -Dz/2;
+
+              x2 = pos;
+              z2 = 1;
+              GetCrossing (x2,z2);
+             AliITSRawClusterSSD cnew;
+             Int_t nstripsP=cluster->GetNumOfDigits();
+             cnew.fMultiplicity=nstripsP;
+             cnew.fMultiplicityN=0;
+             /*
+             if (nstripsP > 100) {
+               printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsP);
+               nstripsP=100;
+             }
+              Int_t k;
+             for(k=0;k<nstripsP;k++) {
+               // check if 'clusterP->GetDigitStripNo(i)' returns 
+               // the digit index and not smth else
+               cnew.fIndexMap[k] = cluster->GetDigitStripNo(k); 
+             } 
+             */
+             cnew.fQErr=sigerr;
+             //cnew.fProbability=0.75; 
+             fITS->AddCluster(2,&cnew);
+             // add the rec point info
+             AliITSRecPoint rnew;
+              rnew.SetX(kconv*(x1+x2)/2);
+              rnew.SetZ(kconv*(z1+z2)/2);
+              rnew.SetQ(sig);
+              rnew.SetdEdX(sig/kdEdXtoQ);
+             rnew.SetSigmaX2( kRMSx* kRMSx);
+             rnew.SetSigmaZ2( kRMSz* kRMSz);
+              rnew.SetProbability(0.75);
+              fITS->AddRecPoint(rnew);
+             /*
+              fPointsM->AddLast( (TObject*) 
+                   new AliITSRecPointSSD((x1+x2)/2 ,0,0,0,(z1+z2)/2,0,sig,sigerr,fLayer,fLad,fDet,cluster, 0.75) );
+             */
+
+              if(debug) cout<<"\n"<<": SINGLE SIDE ImpactPoint Created: X = "
+                  <<(x1+x2)/2<<" Z = "<<(z1+z2)/2<<";   Pos = "<<pos;
+            }
+        }
+    }
+
+  for(i=0;i<fNClusterN;i++)
+    {
+      // printf("N side cluster: cluster number %d\n",i);
+      cluster = GetNSideCluster(i);
+      if (!cluster->IsConsumed())
+        {
+          if( (pos = cluster->GetPosition()) < fSFF)
+            {
+              sig = cluster->GetTotalSignal();
+              
+              sig += sig*PNsignalRatio;
+              
+              sigerr = cluster->GetTotalSignalError();
+              
+              x1 = -Dx/2 + pos *fPitch;
+              z1 = Dz/2;
+
+              x2 = 1;
+              z2 = pos;
+              
+              GetCrossing (x2,z2);
+             AliITSRawClusterSSD cnew;
+             Int_t nstripsN=cluster->GetNumOfDigits();
+             cnew.fMultiplicity=0;
+             cnew.fMultiplicityN=nstripsN;
+             /*
+             if (nstripsN > 100) {
+               printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsN);
+               nstripsN=100;
+             }
+              Int_t k;
+             for(k=0;k<nstripsN;k++) {
+               // check if 'clusterP->GetDigitStripNo(i)' returns 
+               // the digit index and not smth else
+               cnew.fIndexMapN[k] = cluster->GetDigitStripNo(k); 
+             } 
+             */
+             cnew.fQErr=sigerr;
+             //cnew.fProbability=0.75; 
+             fITS->AddCluster(2,&cnew);
+             // add the rec point info
+             AliITSRecPoint rnew;
+              rnew.SetX(kconv*(x1+x2)/2);
+              rnew.SetZ(kconv*(z1+z2)/2);
+              rnew.SetQ(sig);
+              rnew.SetdEdX(sig/kdEdXtoQ);
+             rnew.SetSigmaX2( kRMSx* kRMSx);
+             rnew.SetSigmaZ2( kRMSz* kRMSz);
+              rnew.SetProbability(0.75);
+              fITS->AddRecPoint(rnew);
+             /*
+              fPointsM->AddLast( (TObject*) 
+                   new AliITSRecPointSSD((x1+x2)/2 ,0,0,0,(z1+z2)/2,0,sig,sigerr,fLayer,fLad,fDet,cluster, 0.75) );
+             */
+
+              if(debug) cout<<"\n"<<": SINGLE SIDE ImpactPoint Created: X = "
+                  <<(x1+x2)/2<<" Z = "<<(z1+z2)/2<<";   Pos = "<<pos;
+            }
+        }
+    }
+
+
+}
+
+//_______________________________________________________________________
+
+Bool_t AliITSClusterFinderSSD::GetCrossing (Float_t &P, Float_t &N) 
+{ 
+
+   Float_t Dx = fSegmentation->Dx();
+   Float_t Dz = fSegmentation->Dz();
+
+   //P==X
+   //N==Z
+
+    Float_t dx = 0.1;
+    P *= fPitch;
+    N *= fPitch; 
+    
+    //P = (kZ * fTan + N + P)/2.0;         // x coordinate
+    //N = kZ - (P-N)/fTan;                 // z coordinate
+    
+    if(fTanP + fTanN == 0) return kFALSE;
+
+    N = (N - P + fTanN * Dz) / (fTanP + fTanN);  // X coordinate
+    P = P + fTanP * N;                           // Y coordinate
+
+    P -= Dx/2;
+    N -= Dz/2;
+
+    //   N = -(N - P + kZ/2*(fTanP + fTanN))/(fTanP + fTanN);
+    //  P = (fTanP*(N-kX/2-kZ*fTanN/2) + fTanN*(P-kX/2-kZ*fTanP/2) )/(fTanP + fTanN);
+    
+    if ( ( N < -(Dz/2+dx) ) || ( N > (Dz/2+dx) ) ) return kFALSE;
+    if ( ( P < -(Dx/2+dx) ) || ( P > (Dx/2+dx) ) ) return kFALSE;
+
+    return kTRUE;   
+}
+
+
+//_________________________________________________________________________
+
+void AliITSClusterFinderSSD::GetCrossingError(Float_t& dP, Float_t& dN)
+{
+  Float_t dz, dx;
+  
+  dz = TMath::Abs(( dP + dN )*fPitch/(fTanP + fTanN) );
+  dx = fPitch*(TMath::Abs(dP*(1 - fTanP/(fTanP + fTanN))) +
+               TMath::Abs(dN *fTanP/(fTanP + fTanN) ));
+  
+  dN = dz;
+  dP = dx;
+}
+
+
diff --git a/ITS/AliITSClusterFinderSSD.h b/ITS/AliITSClusterFinderSSD.h
new file mode 100644 (file)
index 0000000..e9edd9c
--- /dev/null
@@ -0,0 +1,155 @@
+#ifndef ALIITSCLUSTERFINDERSSD_H
+#define ALIITSCLUSTERFINDERSSD_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+
+#include <TObject.h>
+#include <TArrayS.h>
+#include <TClonesArray.h>
+#include <TRandom.h>
+#include <TMath.h>
+
+#include "AliITS.h"
+#include "AliITSclusterSSD.h"
+#include "AliITSpackageSSD.h"
+#include "AliITSClusterFinder.h"
+
+
+class AliITSClusterFinderSSD: public AliITSClusterFinder 
+{
+    
+public:       
+    
+  AliITSClusterFinderSSD(AliITSsegmentation *seg, TClonesArray *digits, TClonesArray *recp);
+               
+  virtual ~AliITSClusterFinderSSD();
+
+
+  void FindRawClusters();
+
+    
+  void SetAlpha1(Float_t a) {falpha1 =a;}
+  void SetAlpha2(Float_t a) {falpha2 =a;}
+  void SetAlpha3(Float_t a) {falpha3 =a;}
+
+
+
+ protected:
+   
+  void      InitReconstruction();
+  Bool_t    CreateNewRecPoint(Float_t P, Float_t dP, Float_t N, Float_t dN,
+                              Float_t Sig,Float_t dSig,
+                              AliITSclusterSSD *clusterP, AliITSclusterSSD *clusterN,
+                              Stat_t prob);
+  Bool_t   CreateNewRecPoint(AliITSclusterSSD *clusterP, AliITSclusterSSD *clusterN, Stat_t prob);
+  
+  AliITSclusterSSD* GetPSideCluster(Int_t idx);
+  AliITSclusterSSD* GetNSideCluster(Int_t idx);
+  AliITSclusterSSD* GetCluster(Int_t idx, Bool_t side);
+
+
+  void      FindNeighbouringDigits();
+  void      SeparateOverlappedClusters();
+  void      SplitCluster(TArrayI *list, Int_t nsplits, Int_t index, Bool_t side);
+  Int_t     SortDigitsP(Int_t start, Int_t end);
+  Int_t     SortDigitsN(Int_t start, Int_t end);
+  void      FillDigitsIndex();
+  void      SortDigits();
+  void      FillClIndexArrays(Int_t* arrayP, Int_t *arrayN);
+  void      SortClusters(Int_t* arrayP, Int_t *arrayN);
+  Int_t     SortClustersP(Int_t start, Int_t end,Int_t *array);
+  Int_t     SortClustersN(Int_t start, Int_t end,Int_t *array);
+  void      ConsumeClusters();
+  void      ClustersToPackages();
+  void      PackagesToPoints();
+  void      ReconstructNotConsumedClusters();
+  Bool_t    Strip2Local( Float_t stripP, Float_t stripN, Float_t &Z,Float_t &X);
+  Float_t   GetClusterZ(AliITSclusterSSD* clust);
+  Bool_t    IsCrossing(AliITSclusterSSD* p, AliITSclusterSSD* n);
+  //returns index of best combination in "comb"
+  Int_t     GetBestComb(Int_t** comb,Int_t Ncomb, Int_t Ncl, AliITSpackageSSD * pkg);
+
+  //get point that have best signal ratio
+  void      GetBestMatchingPoint(Int_t & ip, Int_t & in, AliITSpackageSSD* pkg );                                      
+  
+  //calculates Distance To Perfect Matching Line
+  Float_t   DistToPML(Float_t psig, Float_t nsig){ return  (TMath::Abs( (7.0*nsig - 8.0*psig )/10.630146) );}
+  
+  
+  Int_t     GetDiff(Float_t *retx, Float_t *rety) {return 0;}
+  
+  void      CalcStepFactor(Float_t Psteo, Float_t Nsteo );
+  
+/*************************************************/
+/**  methods for resolving packages           ****/
+/*************************************************/ 
+//names may not be meaningful for all, see implementations for descriptions
+
+  void      ResolveSimplePackage(AliITSpackageSSD *pkg);
+  void      ResolvePackageWithOnePSideCluster(AliITSpackageSSD *pkg);
+  void      ResolvePackageWithOneNSideCluster(AliITSpackageSSD *pkg);
+  void      ResolveTwoForTwoPackage(AliITSpackageSSD *pkg);
+
+  void      ResolveClusterWithOneCross(AliITSpackageSSD *pkg,
+                                  Int_t clusterIndex, Bool_t clusterSide);
+
+  void      ResolvePClusterWithOneCross(AliITSpackageSSD *pkg, Int_t clusterIndex);
+  void      ResolveNClusterWithOneCross(AliITSpackageSSD *pkg, Int_t clusterIndex);
+  Bool_t    ResolvePackageBestCombin(AliITSpackageSSD *pkg);
+  void      ResolveOneBestMatchingPoint(AliITSpackageSSD *pkg);
+
+  Bool_t GetCrossing(Float_t &x, Float_t &z);     //x, y of strips crossing
+  void   GetCrossingError(Float_t&, Float_t&);    //x, y of strips crossing errors
+
+  // Data memebers
+
+  AliITS             *fITS;         //Pointer to AliITS object
+  TClonesArray       *fDigits;      //Pointer to TClonesArray of digits
+
+  TClonesArray       *fRecPoints;   //Pointer to TClonesArray of rec points
+  
+       
+  TClonesArray    *fClusterP;    //
+  Int_t            fNClusterP;   //Number of P side clusters in the array
+               
+  TClonesArray    *fClusterN;    //Number of N side clusters in the array
+  Int_t            fNClusterN; 
+    
+  TClonesArray    *fPackages;    //packages  
+  Int_t            fNPackages;
+    
+  TArrayI         *fDigitsIndexP;       //Digits on P side
+  Int_t            fNDigitsP;           //Number of Digits on P side
+               
+  TArrayI         *fDigitsIndexN;       //Digits on N side
+  Int_t            fNDigitsN;           //Number of Digits on N side
+
+
+  Float_t          fPitch;              //Strip pitch
+  Float_t          fTanP;               //Pside stereo angle tangent
+  Float_t          fTanN;               //Nside stereo angle tangent
+
+/*************************************************/
+/**  parameters for reconstruction            ****/
+/**  to be tune when slow simulation raliable ****/
+/*************************************************/ 
+  
+  Float_t falpha1; 
+  Float_t falpha2;
+  Float_t falpha3;
+
+    
+  static const Bool_t SIDEP=kTRUE;
+  static const Bool_t SIDEN=kFALSE;
+  static const Float_t PNsignalRatio = 7./8.;
+  Int_t fSFF;              //forward stepping factor 
+  Int_t fSFB;              //backward stepping factor 
+
+public:
+    ClassDef(AliITSClusterFinderSSD, 1) //Class for clustering and reconstruction of space points in SSDs 
+
+};
+
+
+#endif
diff --git a/ITS/AliITSDetType.cxx b/ITS/AliITSDetType.cxx
new file mode 100644 (file)
index 0000000..d0253ad
--- /dev/null
@@ -0,0 +1,54 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include "AliITSDetType.h"
+
+ClassImp(AliITSDetType)         
+
+AliITSDetType::AliITSDetType() 
+{
+  // constructor
+    fSegmentation=0;
+    fResponse=0;
+    fSimulation=0;
+    fReconst=0;
+}
+
+//__________________________________________________________________________
+AliITSDetType::AliITSDetType(const AliITSDetType &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fReconst = source.fReconst;
+  this->fSimulation = source.fSimulation;
+  this->fResponse = source.fResponse;
+  this->fSegmentation = source.fSegmentation;
+  this->fDigClassName = source.fDigClassName;
+  this->fClustClassName = source.fClustClassName;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSDetType& AliITSDetType::operator=(const AliITSDetType &source){
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fReconst = source.fReconst;
+  this->fSimulation = source.fSimulation;
+  this->fResponse = source.fResponse;
+  this->fSegmentation = source.fSegmentation;
+  this->fDigClassName = source.fDigClassName;
+  this->fClustClassName = source.fClustClassName;
+  return *this;
+  
+}
diff --git a/ITS/AliITSDetType.h b/ITS/AliITSDetType.h
new file mode 100644 (file)
index 0000000..a0b5bec
--- /dev/null
@@ -0,0 +1,93 @@
+#ifndef ALIITSDETTYPE_H
+#define ALIITSDETTYPE_H
+
+
+#include <TString.h>
+#include <TObject.h>
+
+#include "AliITSsegmentation.h"
+#include "AliITSresponse.h"
+
+class AliITSClusterFinder;
+class AliITSsimulation;
+
+class AliITSDetType:public TObject
+{
+
+ public:
+    AliITSDetType();
+    ~AliITSDetType(){
+      //destructor
+    }
+    AliITSDetType(const AliITSDetType &source); // copy constructor
+    AliITSDetType& operator=(const AliITSDetType &source); // assign. operator
+
+// Set the defaults
+  void   Init() {}
+
+//
+  void    SegmentationModel(AliITSsegmentation* thisSegmentation){ 
+    // Configure segmentation model
+    if(fSegmentation) delete fSegmentation;
+    fSegmentation=thisSegmentation;
+  }
+  //
+  void    ResponseModel(AliITSresponse* thisResponse) { 
+    // Configure response model
+    if(fResponse) delete fResponse;
+    fResponse=thisResponse;
+  }
+  //
+  void    SimulationModel(AliITSsimulation *thisSimulation) {
+    // Configure simulation model
+    fSimulation = thisSimulation;
+  }
+  //
+  void    ReconstructionModel(AliITSClusterFinder *thisReconstruction) {
+// Configure reconstruction model
+      fReconst = thisReconstruction;
+  }
+  void    ClassNames(TString digit, TString cluster) { 
+    // Set class names for digits and clusters
+    fDigClassName=digit; fClustClassName=cluster; 
+  } 
+  
+  AliITSsegmentation*      &GetSegmentationModel(){
+    //  Get reference to segmentation model
+    return fSegmentation;
+  }
+  AliITSresponse*          &GetResponseModel(){
+    //  Get reference to response model
+    return fResponse;
+  }
+  AliITSsimulation*        &GetSimulationModel(){
+    //  Get reference to simulation model
+    return fSimulation;
+  }
+  AliITSClusterFinder*     &GetReconstructionModel(){
+    //  Get reference to hit reconstruction model
+    return fReconst;
+  }
+  //  
+  
+  void GetClassNames(const char *&digit, const char *&cluster) 
+    { 
+      // Get class names for digits and rec points
+      digit=fDigClassName; cluster=fClustClassName; 
+    } 
+  
+protected:
+  
+  AliITSClusterFinder  *fReconst;          // cluster finder
+  AliITSsimulation     *fSimulation;       // simulation
+  AliITSresponse       *fResponse;         // response
+  AliITSsegmentation   *fSegmentation;     // segmentation
+  
+  TString              fDigClassName;      // string
+  TString              fClustClassName;    // string
+  
+  ClassDef(AliITSDetType,1)
+    
+    };
+
+#endif
diff --git a/ITS/AliITSHuffman.cxx b/ITS/AliITSHuffman.cxx
new file mode 100644 (file)
index 0000000..2c3cdaa
--- /dev/null
@@ -0,0 +1,298 @@
+////////////////////////////////////////////////
+//  RawData classes for set:ITS               //
+////////////////////////////////////////////////
+
+#include <TMath.h>
+
+#include <iostream.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "AliITSHuffman.h"
+#include "AliITSRawData.h"
+
+ClassImp(AliITSHNode)
+
+//_____________________________________________________________________________
+
+AliITSHNode::AliITSHNode()
+{
+  // constructor
+    fLeft=0;
+    fRight=0;
+    fFather=0;
+}
+//_____________________________________________________________________________
+
+AliITSHNode::AliITSHNode(UChar_t sym, ULong_t freq)
+{
+  // constructor
+    fSymbol=sym;
+    fFrequency=freq;
+    fLeft=0;
+    fRight=0;
+    fFather=0;
+}
+
+//__________________________________________________________________________
+AliITSHNode::AliITSHNode(const AliITSHNode &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fSymbol = source.fSymbol;
+  this->fFrequency = source.fFrequency;
+  this->fLeft = source.fLeft;
+  this->fRight = source.fRight;
+  this->fFather = source.fFather;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSHNode& 
+  AliITSHNode::operator=(const AliITSHNode &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fSymbol = source.fSymbol;
+  this->fFrequency = source.fFrequency;
+  this->fLeft = source.fLeft;
+  this->fRight = source.fRight;
+  this->fFather = source.fFather;
+  return *this;
+}
+
+//____________________________________________
+Int_t AliITSHNode::Compare(TObject *obj)
+{
+  // function called by Sort method of TObjArray
+
+         AliITSHNode *node=(AliITSHNode *)obj;
+        ULong_t f=fFrequency;
+         ULong_t fo=node->fFrequency;
+         if (f>fo) return 1;
+         else if (f<fo) return -1;
+         else return 0;
+}
+//_____________________________________________________________________________
+
+
+ClassImp(AliITSHTable)
+
+//_____________________________________________________________________________
+
+AliITSHTable::AliITSHTable()
+{
+  // constructor
+    fCodeLen=0;
+    fCode=0;
+    fHNodes=0;
+    fNnodes=0;
+   
+}
+//_____________________________________________________________________________
+
+AliITSHTable::AliITSHTable(Int_t size)
+{
+  //
+  // Creates the look-up table for the 1D compression
+  //
+
+  //initialise
+
+  fSize=size;
+  fCodeLen = new UChar_t[fSize]; 
+  fCode = new ULong_t[fSize]; 
+  fHNodes = new TObjArray;
+  fNnodes=0;
+  fSym= new Short_t[fSize];
+  for(Short_t i=0;i<fSize;i++) {
+       fSym[i]=i;
+  }
+  Clear(); 
+
+}
+
+//__________________________________________________________________________
+AliITSHTable::AliITSHTable(const AliITSHTable &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fSize = source.fSize;
+  this->fCodeLen = source.fCodeLen;
+  this->fCode = source.fCode;
+  this->fSym = source.fSym;
+  this->fHNodes = source.fHNodes;
+  this->fNnodes = source.fNnodes;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSHTable& 
+  AliITSHTable::operator=(const AliITSHTable &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fSize = source.fSize;
+  this->fCodeLen = source.fCodeLen;
+  this->fCode = source.fCode;
+  this->fSym = source.fSym;
+  this->fHNodes = source.fHNodes;
+  this->fNnodes = source.fNnodes;
+  return *this;
+}
+
+//_____________________________________________________________________________
+void AliITSHTable::GetFrequencies(Int_t len, UChar_t *stream)
+{
+  // get frequencies
+  printf("Get Frequencies: sym %p \n",fSym);
+
+  // use temporarily the fCode array to store the frequencies
+  Int_t i;
+  for(i=0; i< len; i++) {
+      Int_t idx=TMath::BinarySearch(fSize,fSym,(Short_t)stream[i]);
+      if (idx == (Int_t)stream[i]) fCode[idx]++;
+      // test
+      if(idx==134) cout<< "idx fCode[idx]  "<<idx<<" "<<fCode[idx]<<endl;
+      //printf("idx,fCode[i] %d %d\n",idx,(Int_t)fCode[idx]);
+  }
+
+
+}
+
+
+//_____________________________________________________________________________
+void AliITSHTable::BuildHTable()
+{
+  // build Htable
+
+  Int_t i;
+  for(i=0; i< fSize; i++) {
+    //printf("i,fCode[i] %d %d\n",i,(Int_t)fCode[i]);
+     if (fCode[i] > 0) {
+        fNnodes++;
+        cout<< "i fCode[i] fNnodes "<<i<<" "<<fCode[i]<<" "<<fNnodes<<endl;
+       //printf("i, fCode[i] fNnodes %d %d %d\n",i,fCode[i],fNnodes);
+        fHNodes->Add(new AliITSHNode((UChar_t)i,fCode[i]));
+     }
+  }
+
+  Int_t nentries=fHNodes->GetEntriesFast();
+  Int_t nindex=nentries-1;  
+  printf("nentries fNnodes nindex %d %d %d\n",nentries,fNnodes,nindex);
+
+  while (nindex > 0) 
+    {
+
+     fHNodes->Sort(nindex);
+     AliITSHNode *aux = new AliITSHNode(0,0);
+     AliITSHNode *node= (AliITSHNode*)fHNodes->UncheckedAt(nindex-1);
+     AliITSHNode *node1= (AliITSHNode*)fHNodes->UncheckedAt(nindex);
+     aux->fLeft = node;
+     aux->fRight = node1;
+     aux->fFrequency = node->fFrequency + node1->fFrequency;
+     printf("symbol symbol1 freq freq1 %d %d %d %d\n",(int)node->fSymbol,(int)node1->fSymbol,(int)node->fFrequency,(int)node1->fFrequency);
+     cout << "aux - frequency "<< (Int_t)(aux->fFrequency) <<endl;
+     fHNodes->RemoveAt(nindex-1);
+     fHNodes->AddAt(aux,nindex-1);
+     nindex--;
+     printf("nindex, obj at nindex %d %p \n",nindex,(AliITSHNode*)fHNodes->UncheckedAt(nindex));
+
+    }
+
+    Clear();
+
+    AliITSHNode *start= (AliITSHNode*)fHNodes->UncheckedAt(0);
+    SpanTree(start,0,0);
+    
+    // check the Huffman table
+
+    cout << "...Done, Huffman Table is: \n";
+    Int_t c;
+    for(c=0; c <= 255; c++) {
+      if (fCodeLen[c] > 0) cout << "Symbol " << c << " Coded as " << fCode[c] << " and long " << (int) fCodeLen[c] << " bits.\n"; 
+    }
+
+}
+
+//_____________________________________________________________________________
+AliITSHTable::~AliITSHTable()
+{
+  // HTable
+    printf("HTable destructor !\n");
+    if (fCodeLen) delete[] fCodeLen;
+    if (fCode) delete [] fCode;
+    delete fHNodes;
+}
+
+
+//____________________________________________
+Bool_t AliITSHTable::SpanTree(AliITSHNode *start, ULong_t code, UChar_t len)
+{
+  // span tree
+  AliITSHNode * visited;
+  visited = start;
+
+  printf("outside: code, len %d %d\n",(int)code,(int)len);
+
+  Int_t idx=(Int_t)visited->fSymbol;
+  if (!visited->fLeft) {
+       fCode[idx] = code; 
+       fCodeLen[idx] = len;
+        printf("idx, fCode[idx], fCodeLen[idx] %d %d %d\n",idx,(int)fCode[idx],
+              (int)fCodeLen[idx]);
+       return kTRUE;
+  }
+
+// reccursive stuff
+
+  if (SpanTree(visited->fLeft, code << 1, len + 1)) {
+          printf("code, len %d %d\n",(int)code,(int)len);
+         if (visited->fRight) 
+                  SpanTree(visited->fRight, code << 1 | 0x01, len + 1);
+  }
+  return kTRUE;
+}
+
+//____________________________________________
+void AliITSHTable::ResetHNodes()
+{
+    //
+    // Reset number of HNodes and the HNodes array 
+    //
+       if (fHNodes)  fHNodes->Clear();
+       if (fNnodes)  fNnodes=0;
+
+}
+
+//_____________________________________________________________________________
+void AliITSHTable::Clear()
+{
+  // clear
+    memset(fCodeLen,0,sizeof(UChar_t)*fSize);
+    memset(fCode,0,sizeof(ULong_t)*fSize);
+}
+
+//___________________________________________________________________________
+void AliITSHTable::Streamer(TBuffer &R__b)
+{
+   // Stream an object of class AliITSHTable.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      TObject::Streamer(R__b);
+      R__b >> fSize;
+      R__b.ReadArray(fCodeLen);
+      R__b.ReadArray(fCode);
+      R__b.ReadArray(fSym);
+      R__b >> fHNodes;
+      R__b >> fNnodes;
+   } else {
+      R__b.WriteVersion(AliITSHTable::IsA());
+      TObject::Streamer(R__b);
+      R__b << fSize;
+      R__b.WriteArray(fCodeLen, fSize);
+      R__b.WriteArray(fCode, fSize);
+      R__b.WriteArray(fSym, fSize);
+      R__b << fHNodes;
+      R__b << fNnodes;
+   }
+}
+
diff --git a/ITS/AliITSHuffman.h b/ITS/AliITSHuffman.h
new file mode 100644 (file)
index 0000000..d3649ef
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef AliITSHUFFMAN_H
+#define AliITSHUFFMAN_H
+
+///////////////////////////////////////////////////
+//  Huffman Table associated classes for set:ITS //
+///////////////////////////////////////////////////
+
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+// Attention! Two classes in this file.
+// They have to stay in the same file.
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+#include <TObject.h>
+#include <TObjArray.h>
+
+class AliITSInStream;
+
+class AliITSHNode: public TObject  {
+
+ public:
+
+  UChar_t    fSymbol;        // comment to be written
+  ULong_t    fFrequency;     // comment to be written
+  AliITSHNode     *fLeft;    // comment to be written
+  AliITSHNode     *fRight;   // comment to be written
+  AliITSHNode     *fFather;  // not used
+  
+ public:
+  AliITSHNode();
+  AliITSHNode(UChar_t symbol, ULong_t freq);
+  virtual   ~AliITSHNode() {
+    // destructor
+  }
+  AliITSHNode(const AliITSHNode &source); // copy constructor
+  AliITSHNode& operator=(const AliITSHNode &source); // ass. op.
+
+  Bool_t IsSortable() const {
+    // is sortable
+    return kTRUE;
+  }
+  Int_t Compare(TObject *obj);
+  
+  ClassDef(AliITSHNode,1)     //HuffT node object for set:ITS
+    };
+
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//  Attention! Next class has kept deliberaty in 
+//  the same file as the previous one
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
+//___________________________________________
+class AliITSHTable: public TObject{
+  
+public:
+  AliITSHTable(); 
+  AliITSHTable(Int_t size);
+  virtual   ~AliITSHTable();
+  AliITSHTable(const AliITSHTable &source); // copy constructor
+  AliITSHTable& operator=(const AliITSHTable &source); // ass. op.
+  
+  Int_t  Size() {
+    // size
+    return fSize;
+  }
+  UChar_t   *CodeLen() {
+    // code len
+    return fCodeLen;
+  }
+  ULong_t *Code() {
+    // code
+    return fCode;
+  }
+  TObjArray  *HNodes() {
+    // HNodes
+    return fHNodes;
+  }
+  
+  
+  void GetFrequencies(Int_t len, UChar_t *stream);
+  void BuildHTable();   
+  Bool_t SpanTree(AliITSHNode*start, ULong_t code, UChar_t len);
+  void ResetHNodes();
+  void Clear();
+  
+ protected:
+
+  Int_t          fSize;     // size of the arrays
+  UChar_t       *fCodeLen;  //[fSize] number of bits array
+  ULong_t       *fCode;     //[fSize] coded symbols array
+  
+  Short_t       *fSym;      //[fSize] array of input symbols
+  TObjArray     *fHNodes;   // array of nodes
+  Int_t          fNnodes;   // number of nodes
+
+  ClassDef(AliITSHTable,1)     //Huffman Table  object for set:ITS
+    };
+
+#endif
diff --git a/ITS/AliITSMap.cxx b/ITS/AliITSMap.cxx
new file mode 100644 (file)
index 0000000..ce23b6e
--- /dev/null
@@ -0,0 +1,433 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <TH1.h>
+#include "AliITSMap.h"
+
+ClassImp(AliITSMap)
+
+ClassImp(AliITSMapA1)
+
+AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg)
+{
+  //constructor
+  fSegmentation = seg;
+  fNpz=fSegmentation->Npz();
+  fNpx=fSegmentation->Npx();
+  fMaxIndex=fNpz*fNpx+fNpx;             // 2 halves of detector
+  
+  fHitMap = new Int_t[fMaxIndex];
+  fObjects = 0;
+  ClearMap();
+}
+
+AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg, TObjArray *obj)
+{
+  //constructor
+  fSegmentation = seg;
+  fNpz=fSegmentation->Npz();
+  fNpx=fSegmentation->Npx();
+  fMaxIndex=fNpz*fNpx+fNpx;             // 2 halves of detector
+  
+  fHitMap = new Int_t[fMaxIndex];
+  fObjects =  obj;
+  if (fObjects) fNobjects = fObjects->GetEntriesFast();
+  ClearMap();
+}
+
+
+AliITSMapA1::~AliITSMapA1()
+{
+  //destructor
+  if (fHitMap) delete[] fHitMap;
+}
+
+//__________________________________________________________________________
+AliITSMapA1::AliITSMapA1(const AliITSMapA1 &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fNpx = source.fNpx;
+  this->fNpz = source.fNpz;
+  this->fObjects = source.fObjects;
+  this->fNobjects = source.fNobjects;
+  this->fMaxIndex = source.fMaxIndex;
+  this->fHitMap = source.fHitMap;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSMapA1& 
+  AliITSMapA1::operator=(const AliITSMapA1 &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fNpx = source.fNpx;
+  this->fNpz = source.fNpz;
+  this->fObjects = source.fObjects;
+  this->fNobjects = source.fNobjects;
+  this->fMaxIndex = source.fMaxIndex;
+  this->fHitMap = source.fHitMap;
+  return *this;
+}
+
+void AliITSMapA1::ClearMap()
+{
+  //clear array
+  memset(fHitMap,0,sizeof(int)*fMaxIndex);
+}
+
+void AliITSMapA1::SetArray(TObjArray *obj)
+{
+  // set array of objects
+  fObjects =  obj;
+  if (fObjects) fNobjects = fObjects->GetEntriesFast();
+}
+
+
+Int_t AliITSMapA1::CheckedIndex(Int_t iz, Int_t ix)
+{
+  //check boundaries and return an index in array
+  Int_t index=fNpx*iz+ix;
+  if (index > fMaxIndex) {
+    printf("\n \n \n Try to read/write outside array !!!! \n \n %d %d %d %d %d %d",iz,ix, fMaxIndex, index, fNpz, fNpx);
+    // force crash
+    return  -1;
+  } else {
+    return index;
+  }
+}
+
+
+void  AliITSMapA1::FillMap()
+{
+  // fill array with digits indices
+  Int_t ndigits = fObjects->GetEntriesFast();
+  //printf("MapA1: ndigits fNobjects %d %d \n",ndigits,fNobjects);
+  if (!ndigits) return;
+  
+  AliITSdigit *dig;
+  Int_t ndig;
+  for(ndig=0; ndig<ndigits; ndig++) {
+    dig = (AliITSdigit*)fObjects->UncheckedAt(ndig);
+    //printf("MapA1: ndig fCoord1 fCoord2 %d %d %d \n",dig->fCoord1,dig->fCoord2,ndig);
+    SetHit(dig->fCoord1,dig->fCoord2,ndig);
+  }
+  
+}
+
+void  AliITSMapA1::SetHit(Int_t iz, Int_t ix, Int_t idigit)
+{
+  // set the digit index at a certain position in array
+  fHitMap[CheckedIndex(iz, ix)]=idigit+1;
+}
+
+void AliITSMapA1::DeleteHit(Int_t iz, Int_t ix)
+{
+  // delete an entry in array
+  fHitMap[CheckedIndex(iz, ix)]=0;
+}
+
+void AliITSMapA1::FlagHit(Int_t iz, Int_t ix)
+{
+  // flag an entry in array
+  fHitMap[CheckedIndex(iz, ix)]=
+    -TMath::Abs(fHitMap[CheckedIndex(iz, ix)]);
+}
+
+Int_t AliITSMapA1::GetHitIndex(Int_t iz, Int_t ix)
+{
+  // return the digit index from a specific entry in array
+  return TMath::Abs(fHitMap[CheckedIndex(iz, ix)])-1;
+}
+
+TObject* AliITSMapA1::GetHit(Int_t iz, Int_t ix)
+{
+  // return the pointer to the digit 
+  Int_t index=GetHitIndex(iz,ix);
+  // Force crash if index does not exist ! 
+  return (index <0) ? 0 : fObjects->UncheckedAt(GetHitIndex(iz,ix));
+}
+
+
+Flag_t AliITSMapA1::TestHit(Int_t iz, Int_t ix)
+{
+  // check whether the digit has already been flagged
+  Int_t inf=fHitMap[CheckedIndex(iz, ix)]; 
+  if (inf < 0) {
+    return kUsed;
+  } else if (inf == 0) {
+       return kEmpty;
+  } else {
+    return kUnused;
+    }
+}
+//_______________________________________________________________________
+void AliITSMapA1::Streamer(TBuffer &R__b)
+{
+   // Stream an object of class AliITSMapA1.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      AliITSMap::Streamer(R__b);
+      R__b >> fSegmentation;
+      R__b >> fNpx;
+      R__b >> fNpz;
+      R__b >> fObjects;
+      R__b >> fNobjects;
+      R__b >> fMaxIndex;
+      R__b.ReadArray(fHitMap);
+   } else {
+      R__b.WriteVersion(AliITSMapA1::IsA());
+      AliITSMap::Streamer(R__b);
+      R__b << fSegmentation;
+      R__b << fNpx;
+      R__b << fNpz;
+      R__b << fObjects;
+      R__b << fNobjects;
+      R__b << fMaxIndex;
+      R__b.WriteArray(fHitMap,fMaxIndex);
+   }
+}
+
+//========================================================================
+ClassImp(AliITSMapA2)
+
+  AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg)
+{
+  //constructor
+  fSegmentation = seg;
+  fNpz=fSegmentation->Npz();
+  fNpx=fSegmentation->Npx();
+  fMaxIndex=fNpz*fNpx+fNpx;             // 2 halves of detector
+  
+  fHitMap = new Double_t[fMaxIndex];
+  fMapThreshold=0.;
+  ClearMap();
+}
+
+//--------------------------------------
+AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg, TObjArray *hist, Double_t thresh)
+{
+  //constructor
+  fSegmentation = seg;
+  fNpz=fSegmentation->Npz();
+  fNpx=fSegmentation->Npx();
+  fMaxIndex=fNpz*fNpx+fNpx;             // 2 halves of detector
+  
+  fHitMap = new Double_t[fMaxIndex];
+    fObjects =  hist;
+    if (fObjects) fNobjects = fObjects->GetEntriesFast();
+    fMapThreshold = thresh;
+    ClearMap();
+}
+//--------------------------------------
+
+
+AliITSMapA2::~AliITSMapA2()
+{
+  //destructor
+  if (fHitMap) delete[] fHitMap;
+}
+//--------------------------------------
+
+//__________________________________________________________________________
+AliITSMapA2::AliITSMapA2(const AliITSMapA2 &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fMapThreshold = source.fMapThreshold;
+  this->fHitMap = source.fHitMap;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSMapA2& 
+  AliITSMapA2::operator=(const AliITSMapA2 &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fMapThreshold = source.fMapThreshold;
+  this->fHitMap = source.fHitMap;
+  return *this;
+}
+
+void AliITSMapA2::ClearMap()
+{
+  //clear array
+  memset(fHitMap,0,sizeof(Double_t)*fMaxIndex);
+}
+
+//--------------------------------------
+void  AliITSMapA2::FillMap()
+{
+  
+  // fills signal map from digits - apply a threshold for signal
+   
+  if (!fObjects) return; 
+  
+  Int_t ndigits = fObjects->GetEntriesFast();
+  printf("MapA2: ndigits fNobjects %d %d \n",ndigits,fNobjects);
+  if (!ndigits) return;
+  
+  AliITSdigit *dig;
+  Int_t ndig;
+  for(ndig=0; ndig<ndigits; ndig++) {
+    dig = (AliITSdigit*)fObjects->UncheckedAt(ndig);
+    Double_t signal = (Double_t)(dig->fSignal);
+    if (signal >= fMapThreshold) SetHit(dig->fCoord1,dig->fCoord2,signal);
+  }
+}
+
+//--------------------------------------
+void  AliITSMapA2::SetHit(Int_t iz, Int_t ix, Double_t signal)
+{
+  // set signal at a certain position in array
+  fHitMap[CheckedIndex(iz, ix)]=signal;
+  
+}
+
+//--------------------------------------
+void AliITSMapA2::DeleteHit(Int_t iz, Int_t ix)
+{
+  //set the entry value to zero
+  fHitMap[CheckedIndex(iz, ix)]=0;
+}
+
+//--------------------------------------
+void AliITSMapA2::FlagHit(Int_t iz, Int_t ix)
+{
+  //flag an entry
+  fHitMap[CheckedIndex(iz, ix)]=
+    -1000.*TMath::Abs((Int_t)(fHitMap[CheckedIndex(iz, ix)])+1.);
+  
+}
+
+//--------------------------------------
+Int_t AliITSMapA2::GetHitIndex(Int_t iz, Int_t ix)
+{
+  //return the index of an entry in array 
+  return CheckedIndex(iz, ix);
+}
+
+//--------------------------------------
+TObject* AliITSMapA2::GetHit(Int_t i, Int_t dummy)
+{
+  
+  //return a pointer to the 1D histogram
+  if (fObjects) {
+    
+    return fObjects->UncheckedAt(i); 
+    
+  } else return NULL;
+  
+}
+
+//--------------------------------------
+Double_t AliITSMapA2::GetSignal(Int_t iz, Int_t ix)
+{
+  //get signal in a cell 
+  Int_t index=GetHitIndex(iz,ix);
+  return (index <0) ? 0. : fHitMap[CheckedIndex(iz, ix)];
+}
+
+//--------------------------------------
+Double_t AliITSMapA2::GetSignal(Int_t index)
+{
+  //get signal in a cell 
+  if (index<fMaxIndex) return (index <0) ? 0. : fHitMap[index];
+  else return 0.;
+}
+//--------------------------------------
+Flag_t AliITSMapA2::TestHit(Int_t iz, Int_t ix)
+{
+  // check if the entry has already been flagged
+    Int_t inf=(Int_t)fHitMap[CheckedIndex(iz, ix)];
+    
+    if (inf <= -1000) {
+      return kUsed;
+    } else if (inf == 0) {
+      return kEmpty;
+    } else {
+      return kUnused;
+    }
+}
+
+//--------------------------------------
+void  AliITSMapA2::FillMapFromHist()
+{
+  
+  // fills map from 1D histograms
+  
+  if (!fObjects) return; 
+  
+  // an example
+  Int_t i,j;
+  for(i=0; i<fNobjects; i++) {
+    TH1F *hist =(TH1F *)fObjects->UncheckedAt(i);
+    Int_t nsamples = hist->GetNbinsX();
+    for(j=0; j<nsamples; j++) {
+      Double_t signal = (Double_t)(hist->GetBinContent(j+1));
+      if (signal >= fMapThreshold) SetHit(i,j,signal);
+    }
+  }
+  
+}
+//--------------------------------------
+void  AliITSMapA2::FillHist()
+{
+  
+  // fill 1D histograms from map
+  if (!fObjects) return; 
+  
+  // an example
+  Int_t i,j;
+  for(i=0; i<fNobjects; i++) {
+    TH1F *hist =(TH1F *)fObjects->UncheckedAt(i);
+    for(j=0; j<fNpx; j++) {
+      Double_t signal=GetSignal(i,j);
+      if (signal >= fMapThreshold) hist->Fill((Float_t)j,signal);
+    }
+  }
+  
+}
+//--------------------------------------
+void  AliITSMapA2::ResetHist()
+{
+  //
+  // Reset histograms 
+  //
+  
+  if (!fObjects) return; 
+  
+  Int_t i;
+  for(i=0; i<fNobjects; i++) {
+    if ((*fObjects)[i])    ((TH1F*)(*fObjects)[i])->Reset();
+  }
+  
+}
+//______________________________________________________________________________
+void AliITSMapA2::Streamer(TBuffer &R__b)
+{
+   // Stream an object of class AliITSMapA2.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      AliITSMapA1::Streamer(R__b);
+      R__b.ReadArray(fHitMap);
+      R__b >> fMapThreshold;
+   } else {
+      R__b.WriteVersion(AliITSMapA2::IsA());
+      AliITSMapA1::Streamer(R__b);
+      R__b.WriteArray(fHitMap, fMaxIndex); // fMaxIndex is from AliITSMapA1.
+      R__b << fMapThreshold;
+   }
+}
diff --git a/ITS/AliITSMap.h b/ITS/AliITSMap.h
new file mode 100644 (file)
index 0000000..97ddeee
--- /dev/null
@@ -0,0 +1,119 @@
+#ifndef ALIITSMAP_H
+#define ALIITSMAP_H
+
+
+#include "AliITS.h"
+
+typedef enum {kEmpty, kUsed, kUnused} Flag_t;
+
+//___________________________________________________________________________
+
+class AliITSMap :
+  public TObject {
+
+public:
+  virtual ~AliITSMap() {}
+  virtual  void  FillMap()                                       =0;
+  virtual  void  ClearMap()                                      =0;
+  virtual  void  SetHit(Int_t iz, Int_t ix, Int_t idigit)        =0;
+  virtual  void  DeleteHit(Int_t iz, Int_t ix)                   =0;
+  virtual  void   FlagHit(Int_t iz, Int_t ix)                    =0;    
+  virtual Int_t  GetHitIndex(Int_t iz, Int_t ix)                 =0;
+  virtual TObject * GetHit(Int_t iz, Int_t ix)                   =0;
+  virtual Flag_t TestHit(Int_t iz, Int_t ix)                     =0;
+  virtual Double_t  GetSignal(Int_t iz, Int_t ix)                =0;
+  
+  ClassDef(AliITSMap,1) //virtual base class for ITS Hit/Digit Map
+
+    };
+
+
+class AliITSMapA1 :
+  public AliITSMap 
+{
+  
+public:
+  AliITSMapA1() {
+    // constructor
+  }
+  AliITSMapA1(AliITSsegmentation *seg);
+  AliITSMapA1(AliITSsegmentation *seg, TObjArray *dig);
+  AliITSMapA1(const AliITSMapA1 &source); // copy constructor
+  AliITSMapA1& operator=(const AliITSMapA1 &source); // assignment operator
+  
+  virtual ~AliITSMapA1();
+  virtual  void  FillMap();
+  virtual  void  ClearMap();    
+  virtual Double_t  GetSignal(Int_t iz, Int_t ix) {
+    // get signal
+    return 0.;
+  }
+  virtual  void  SetHit(Int_t iz, Int_t ix, Int_t idigit);
+  virtual void  DeleteHit(Int_t iz, Int_t ix);
+  virtual Int_t  GetHitIndex(Int_t iz, Int_t ix);
+  virtual TObject*  GetHit(Int_t iz, Int_t ix);
+  virtual  void  FlagHit(Int_t iz, Int_t ix);    
+  virtual Flag_t TestHit(Int_t iz, Int_t ix);
+  Int_t  CheckedIndex(Int_t iz, Int_t ix);
+  Int_t   MaxIndex() {
+    // max index
+    return fMaxIndex;
+  }
+  void SetArray(TObjArray *obj);
+  
+protected:
+  AliITSsegmentation *fSegmentation;   // segmentation class
+  Int_t fNpx;                          // fNpx
+  Int_t fNpz;                          // fNpz
+  TObjArray  *fObjects;                // object
+  Int_t fNobjects;                     // nu of object
+  Int_t fMaxIndex;                     // max index
+  
+private:
+  Int_t *fHitMap;                      // hit map
+
+  ClassDef(AliITSMapA1,1) // Implements Hit/Digit Map for SDD - read tree
+    };
+
+
+class AliITSMapA2 :
+public AliITSMapA1 
+{
+
+public:
+  AliITSMapA2(AliITSsegmentation *seg);
+  AliITSMapA2(AliITSsegmentation *seg, TObjArray *hist,Double_t thresh);
+  virtual ~AliITSMapA2();
+  AliITSMapA2(const AliITSMapA2 &source); // copy constructor
+  AliITSMapA2& operator=(const AliITSMapA2 &source); // assignment operator
+  virtual  void  FillMap();
+  virtual  void  ClearMap();    
+  virtual  void  SetHit(Int_t iz, Int_t ix, Int_t signal){
+    // set hit
+  }
+  virtual  void  FlagHit(Int_t iz, Int_t ix);    
+  virtual  void  DeleteHit(Int_t iz, Int_t ix);
+  virtual Int_t  GetHitIndex(Int_t iz, Int_t ix);
+  virtual TObject * GetHit(Int_t iz, Int_t dummy);
+  virtual Flag_t TestHit(Int_t iz, Int_t ix);
+  virtual Double_t  GetSignal(Int_t iz, Int_t ix);
+  void  SetHit(Int_t iz, Int_t ix, Double_t signal);
+  Double_t  GetSignal(Int_t index);
+
+private:
+  Double_t *fHitMap;        // fHitMap
+  Double_t fMapThreshold;   // fMapThreshold
+
+  void  FillMapFromHist();
+  void  FillHist();
+  void  ResetHist();
+  
+  ClassDef(AliITSMapA2,1) // Implements Signal Map for SDD -fill or read hist
+    };
+
+
+#endif 
+
+
+
+
diff --git a/ITS/AliITSRawCluster.cxx b/ITS/AliITSRawCluster.cxx
new file mode 100644 (file)
index 0000000..668518a
--- /dev/null
@@ -0,0 +1,145 @@
+#include <iostream.h>
+#include <TMath.h>
+#include "AliITSRawCluster.h"
+
+ClassImp(AliITSRawCluster)
+ClassImp(AliITSRawClusterSDD)
+//--------------------------------------
+AliITSRawClusterSDD::AliITSRawClusterSDD(Int_t wing, Float_t Anode,Float_t Time,Float_t Charge,Float_t PeakAmplitude,Float_t Asigma, Float_t Tsigma,Float_t DriftPath,Float_t AnodeOffset,Int_t Samples) {
+  // constructor
+  fWing = wing;
+  fAnode = Anode;
+  fTime = Time;
+  fQ = Charge;
+  fPeakAmplitude = PeakAmplitude;
+  fNanodes = 1;
+  fNsamples = Samples;
+  Int_t sign = 1;
+  Int_t i;
+  for(i=0;i<fWing; i++) sign*=(-1);
+  fX = DriftPath*sign/10000.;
+  fZ = AnodeOffset/10000.;
+}
+
+//----------------------------------------
+void AliITSRawClusterSDD::Add(AliITSRawClusterSDD* clJ) {
+  // add
+  fAnode = (fAnode*fQ + clJ->A()*clJ->Q())/(fQ+clJ->Q());
+  fTime = (fTime*fQ + clJ->T()*clJ->Q())/(fQ+clJ->Q());
+  fX = (fX*fQ + clJ->X()*clJ->Q())/(fQ+clJ->Q());
+  fZ = (fZ*fQ + clJ->Z()*clJ->Q())/(fQ+clJ->Q());
+  fQ += clJ->Q();
+  fNsamples += (Int_t) (clJ->Samples());
+  (fNanodes)++;
+  if(clJ->PeakAmpl() > fPeakAmplitude) fPeakAmplitude = clJ->PeakAmpl();
+  
+  return;
+} 
+//--------------------------------------
+Bool_t AliITSRawClusterSDD::Brother(AliITSRawClusterSDD* cluster,Float_t danode,Float_t dtime) {
+  // brother
+  Bool_t brother = kTRUE;
+  if(fWing != cluster->W()) return brother = kFALSE;
+  if(TMath::Abs(fTime-cluster->T()) > dtime) return brother = kFALSE;
+  if(TMath::Abs(fAnode-cluster->A()) > danode) return brother = kFALSE;
+  return brother;
+}
+
+//--------------------------------------
+void AliITSRawClusterSDD::Print() {
+  // print
+  cout << ", Anode " << fAnode << ", Time: " << fTime << ", Charge: " << fQ;
+  cout << ", Samples: " << fNsamples;
+  cout << ", X: " << fX << ", Z: " << fZ << endl;
+}
+//--------------------------------------
+
+
+ClassImp(AliITSRawClusterSPD)
+  //--------------------------------------
+
+  AliITSRawClusterSPD::AliITSRawClusterSPD(Float_t clz,Float_t clx,Float_t Charge,Int_t ClusterSizeZ,Int_t ClusterSizeX,Int_t xstart,Int_t xstop,Int_t xstartf,Int_t xstopf,Float_t zstart,Float_t zstop,Int_t zend) {
+  // constructor
+  
+  fZ = clz;
+  fX = clx;
+  fQ = Charge;
+  fNClZ = ClusterSizeZ;
+  fNClX = ClusterSizeX;
+  fXStart = xstart;
+  fXStop = xstop;
+  fXStartf = xstartf;
+  fXStopf = xstopf;
+  fZStart = zstart;
+  fZStop = zstop;
+  fZend = zend;
+}
+
+//--------------------------------------
+void AliITSRawClusterSPD::Add(AliITSRawClusterSPD* clJ) {
+  // Recolculate the new center of gravity coordinate and cluster sizes
+  // in both directions after grouping of clusters
+  
+  if(this->fZStop < clJ->ZStop()) this->fZStop = clJ->ZStop();  
+  
+  this->fZ = (this->fZ + clJ->Z())/2.;
+  this->fX = (this->fX + clJ->X())/2.;
+  this->fQ = this->fQ + clJ->Q();
+  
+  this->fXStart = clJ->XStart(); // for a comparison with the next
+  this->fXStop = clJ->XStop();   // z column
+  
+  if(this->fXStartf > clJ->XStartf()) this->fXStartf = clJ->XStartf();
+  if(this->fXStopf < clJ->XStopf()) this->fXStopf = clJ->XStopf();
+  if(this->fZend < clJ->Zend()) this->fZend = clJ->Zend();
+  this->fNClX = this->fXStopf - this->fXStartf + 1; 
+  (this->fNClZ)++;
+  
+  return;
+} 
+
+//--------------------------------------
+Bool_t AliITSRawClusterSPD::Brother(AliITSRawClusterSPD* cluster,Float_t dz,Float_t dx) {
+  // fXStart, fXstop and fZend information is used now instead of dz and dx
+  // to check an absent (or a present) of the gap between two pixels in 
+  // both x and z directions. The increasing order of fZend is used.
+  
+  Bool_t brother = kFALSE;  
+  Bool_t test2 = kFALSE;  
+  Bool_t test3 = kFALSE;  
+  
+  // Diagonal clusters are included:
+  if(fXStop >= (cluster->XStart() -1) && fXStart <= (cluster->XStop()+1)) test2 = kTRUE;
+  
+  // Diagonal clusters are excluded:   
+  //       if(fXStop >= cluster->XStart() && fXStart <= cluster->XStop()) test2 = kTRUE;
+  if(cluster->Zend() == (fZend + 1)) test3 = kTRUE; 
+  if(test2 && test3) {
+    // cout<<"test 2,3 0k, brother = true "<<endl;
+    return brother = kTRUE;
+  }
+  return brother;
+}
+
+//--------------------------------------
+void AliITSRawClusterSPD::Print() 
+{
+  // print
+  cout << ", Z: " << fZ << ", X: " << fX << ", Charge: " << fQ<<endl;
+  cout << " Z cluster size: " << fNClZ <<", X cluster size "<< fNClX <<endl;
+  cout <<" XStart, XStop, XStartf,XStopf,Zend ="<<fXStart<<","<<fXStop<<","<<fXStartf<<","<<fXStopf<<","<<fZend<<endl;
+  
+}
+
+
+ClassImp(AliITSRawClusterSSD)
+  //--------------------------------------
+  AliITSRawClusterSSD::AliITSRawClusterSSD(Float_t Prob,Int_t Sp,Int_t Sn) {  
+  // constructor
+  //fProbability   = Prob;
+  fMultiplicity  = Sp;
+  fMultiplicityN = Sn;
+  
+}
diff --git a/ITS/AliITSRawCluster.h b/ITS/AliITSRawCluster.h
new file mode 100644 (file)
index 0000000..9e194b6
--- /dev/null
@@ -0,0 +1,269 @@
+#ifndef ALIITSRAWCLUSTER_H
+#define ALIITSRAWCLUSTER_H 
+
+
+////////////////////////////////////////////////////
+//  Cluster classes for set:ITS                   //
+////////////////////////////////////////////////////
+
+#include <TObject.h>
+
+
+class AliITSRawCluster : public TObject {
+  
+  // this class is subject to changes ! - info used for declustering 
+  // and  eventual debugging
+  
+public:
+  
+  AliITSRawCluster() {
+    /*
+      for (int k=0;k<100;k++) {
+      fIndexMap[k]=-1;
+      }
+      fNcluster[0]=fNcluster[1]=-1;
+      fChi2=-1; 
+    */
+    fMultiplicity=0;
+  }
+  
+  virtual ~AliITSRawCluster() {
+    // destructor
+  }
+  virtual Bool_t IsSortable() const {
+    // is sortable
+    return kTRUE;
+  }
+  
+public:
+
+  Int_t       fMultiplicity;      // cluster multiplicity
+  //Int_t       fIndexMap[100];     // indices of digits
+  //Int_t       fNcluster[2];
+  //Float_t     fChi2;
+  
+  ClassDef(AliITSRawCluster,1)  // AliITSRawCluster class
+    };
+
+//---------------------------------------------
+class AliITSRawClusterSPD : public AliITSRawCluster {
+  
+  // these classes are subject to changes - keep them temporarily for
+  // compatibility !!!
+  
+public:
+  
+  AliITSRawClusterSPD() {
+    // constructor
+    fX=fZ=fQ;
+    fZStart=fZStop;
+    fNClZ=fNClX=fXStart=fXStop=fXStartf=fXStopf=fZend;
+       }
+  
+  AliITSRawClusterSPD(Float_t clz,Float_t clx,Float_t Charge,
+                     Int_t ClusterSizeZ,Int_t ClusterSizeX,Int_t xstart,Int_t xstop,
+                     Int_t xstartf,Int_t xstopf,Float_t zstart,Float_t zstop,Int_t zend);
+  virtual ~AliITSRawClusterSPD() {
+    // destructor
+  }
+  
+  void Add(AliITSRawClusterSPD* clJ); 
+  Bool_t Brother(AliITSRawClusterSPD* cluster,Float_t dz,Float_t dx);
+  void Print();
+  // Getters
+  Float_t Q() const {
+    // Q
+    return fQ ;
+  }
+  Float_t Z() const {
+    // Z
+    return fZ ;
+  }
+  Float_t X() const {
+    // X
+    return fX ;
+  }
+  Float_t NclZ() const {
+    // NclZ
+    return fNClZ ;
+  }
+  Float_t NclX() const {
+    // NclX
+    return fNClX ;
+  }
+  Int_t   XStart() const {
+    //XStart
+    return fXStart;
+  }
+  Int_t   XStop() const {
+    //XStop
+    return fXStop;
+  }
+  Int_t   XStartf() const {
+    //XStartf
+    return fXStartf;
+  }
+  Int_t   XStopf() const {
+    //XStopf
+    return fXStopf;
+  }
+  Float_t ZStart() const {
+    //ZStart
+    return fZStart;
+  }
+  Float_t ZStop() const {
+    //ZStop
+    return fZStop;
+  }
+  Int_t   Zend() const {
+    //Zend
+    return fZend;
+  }
+  
+protected:
+  
+  Float_t   fX;                 // X of cluster
+  Float_t   fZ;                 // Z of cluster
+  Float_t   fQ;                 // Q of cluster
+  Int_t     fNClZ;        // Cluster size in Z direction
+  Int_t     fNClX;        // Cluster size in X direction
+  Int_t     fXStart;      // number of first pixel in cluster
+  Int_t     fXStop;       // number of last pixel in cluster
+  Int_t     fXStartf;     // number of first pixel in full cluster
+  Int_t     fXStopf;      // number of last pixel in full cluster
+  Float_t   fZStart;      // number of first pixel in cluster
+  Float_t   fZStop;       // number of last pixel in cluster
+  Int_t     fZend;        // Zend
+  
+  ClassDef(AliITSRawClusterSPD,1)  // AliITSRawCluster class for SPD
+
+    };
+
+//---------------------------------------------
+class AliITSRawClusterSDD : public AliITSRawCluster {
+  
+public:
+  
+  AliITSRawClusterSDD() {
+    // constructor
+    fX=fZ=fQ;
+    fWing=fNsamples=0;
+    fNanodes=1;
+    fAnode=fTime=fPeakAmplitude=0;
+  }
+  
+  AliITSRawClusterSDD(Int_t wing, Float_t Anode,Float_t Time,Float_t Charge,
+                     Float_t PeakAmplitude,Float_t Asigma, Float_t Tsigma,Float_t DriftPath, Float_t AnodeOffset,Int_t Samples);
+  virtual ~AliITSRawClusterSDD() {
+    // destructor
+  }
+  
+  void Add(AliITSRawClusterSDD* clJ); 
+  Bool_t Brother(AliITSRawClusterSDD* cluster,Float_t dz,Float_t dx);
+  void Print();
+  // Getters
+  Float_t X() const {
+    //X
+    return fX ;
+  }
+  Float_t Z() const {
+    //Z
+    return fZ ;
+  }
+  Float_t Q() const {
+    //Q
+    return fQ ;
+  }
+  Float_t A() const {
+    //A
+    return fAnode ;
+  }
+  Float_t T() const {
+    //T
+    return fTime ;
+  }
+  Float_t W() const {
+    //W
+    return fWing ;
+  }
+  Int_t Anodes() const {
+    //Anodes
+    return fNanodes ;
+  }
+  Int_t Samples() const {
+    //Samples
+    return fNsamples ;
+  }
+  Float_t PeakAmpl() const {
+    //PeakAmpl
+    return fPeakAmplitude ;
+  }
+  
+protected:
+  
+  Float_t   fX;                 // X of cluster
+  Float_t   fZ;                 // Z of cluster
+  Float_t   fQ;                 // Q of cluster
+  Int_t     fWing;              // Wing number
+  Float_t   fAnode;             // Anode number
+  Float_t   fTime;              // Drift Time
+  Float_t   fPeakAmplitude;     // Peak Amplitude
+  Int_t     fNanodes;           // N of anodes used for the cluster
+  Int_t     fNsamples;          // N of samples used for the cluster
+  
+  ClassDef(AliITSRawClusterSDD,1)  // AliITSRawCluster class for SDD
+    };
+
+//-----------------------------------------
+class AliITSRawClusterSSD : public AliITSRawCluster {
+    
+public:
+  
+  AliITSRawClusterSSD() {
+    /*
+      for (int k=0;k<100;k++) {
+      fIndexMapN[k]=-1;
+      }
+    */
+    fMultiplicityN=0;
+    // fProbability=0;
+    fQErr=0; 
+    //fChi2N=-1;
+    fStatus=-1;
+  }
+  AliITSRawClusterSSD(Float_t Prob,Int_t Sp,Int_t Sn);
+  virtual ~AliITSRawClusterSSD() {
+    // destructor
+  }
+  
+  Int_t  GetStatus() const {
+    // get status
+    return fStatus;
+  }
+  void   SetStatus(Int_t status) {
+    // set status
+    fStatus=status;
+  }
+
+   
+public:
+  // Float_t fProbability;    // The probability that this is a "real" point
+  //Int_t   fIndexMapN[100];  // indices of digits for Nside - the corresponding
+                                // info for P side is carried in the base class
+  //Float_t fChi2N;
+  
+  Int_t   fMultiplicityN;  // The number of N side strips involved 
+  // in this point calculations
+  Int_t   fStatus;         // Flag status : 0 - real point
+  //               1 - ghost 
+  //               2 - EIC ? 
+  //               3 - single side 
+  
+  Float_t fQErr;           // Total charge error
+  ClassDef(AliITSRawClusterSSD,1)  // AliITSRawCluster class for SSD
+
+};
+
+
+#endif
diff --git a/ITS/AliITSRawData.cxx b/ITS/AliITSRawData.cxx
new file mode 100644 (file)
index 0000000..54ae9ae
--- /dev/null
@@ -0,0 +1,192 @@
+////////////////////////////////////////////////
+//  RawData classes for set:ITS               //
+////////////////////////////////////////////////
+
+
+#include "AliITSRawData.h"
+
+ClassImp(AliITSRawData)
+
+ClassImp(AliITSInStream)
+
+//_____________________________________________________________________________
+
+AliITSInStream::AliITSInStream()
+{
+  //default constructor
+  fStreamLen=0;
+  fInStream=0;
+}
+//_____________________________________________________________________________
+
+AliITSInStream::AliITSInStream(ULong_t length)
+{
+  //
+  // Creates a stream of unsigned chars
+  //
+  
+  fStreamLen = length;
+  fInStream = new UChar_t[length]; 
+  
+  ClearStream(); 
+  
+}
+
+//_____________________________________________________________________________
+AliITSInStream::~AliITSInStream()
+{
+  //destructor
+  if (fInStream) delete[] fInStream;
+}
+
+//__________________________________________________________________________
+AliITSInStream::AliITSInStream(const AliITSInStream &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fStreamLen = source.fStreamLen;
+  this->fInStream = source.fInStream;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSInStream& 
+  AliITSInStream::operator=(const AliITSInStream &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fStreamLen = source.fStreamLen;
+  this->fInStream = source.fInStream;
+  return *this;
+}
+
+//_____________________________________________________________________________
+void AliITSInStream::ClearStream()
+{
+  //clear the array
+  memset(fInStream,0,sizeof(UChar_t)*fStreamLen);
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliITSInStream::CheckCount(ULong_t count) {
+  //check boundaries
+  if (count <= (ULong_t)fStreamLen) return kTRUE;
+  else {
+    Error("CheckCount", "actual size is %d, the necessary size is %d",fStreamLen,count);
+    return kFALSE;
+  }
+}
+
+//____________________________________________________________________________
+void AliITSInStream::Streamer(TBuffer &R__b){
+  // Stream an object of class AliITSInStream.
+  
+  static unsigned char *array;
+  static Bool_t make=kTRUE;
+  
+  if (R__b.IsReading()) {
+         R__b >> fStreamLen;
+         //printf("Streamer: fStreamLen %d\n",fStreamLen);
+          if (make) array=new unsigned char[fStreamLen];
+          make=kFALSE;
+          memset(array,0,sizeof(UChar_t)*fStreamLen);
+          fInStream=array;
+         R__b.ReadFastArray(fInStream,fStreamLen);
+         
+  } else {
+    R__b << fStreamLen;
+    R__b.WriteFastArray(fInStream,fStreamLen);
+  }
+}
+
+
+
+ClassImp(AliITSOutStream)
+  
+  //_______________________________________________________________________
+  
+  AliITSOutStream::AliITSOutStream() {
+  //default constructor
+  fStreamLen=0;
+  fOutStream=0;
+}
+
+//__________________________________________________________________________
+
+AliITSOutStream::AliITSOutStream(ULong_t length) {
+  //
+  // Creates a stream of unsigned chars
+  //
+  
+  fStreamLen = length;
+  fOutStream = new ULong_t[length];  
+  ClearStream(); 
+  
+}
+
+//_____________________________________________________________________________
+AliITSOutStream::~AliITSOutStream()
+{
+  //destructor
+  if (fOutStream) delete[] fOutStream;
+}
+
+//__________________________________________________________________________
+AliITSOutStream::AliITSOutStream(const AliITSOutStream &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fStreamLen = source.fStreamLen;
+  this->fOutStream = source.fOutStream;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSOutStream& 
+  AliITSOutStream::operator=(const AliITSOutStream &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fStreamLen = source.fStreamLen;
+  this->fOutStream = source.fOutStream;
+  return *this;
+}
+
+//_____________________________________________________________________________
+void AliITSOutStream::ClearStream()
+{
+  // clear stream
+  memset(fOutStream,0,sizeof(ULong_t)*fStreamLen);
+}
+
+//_____________________________________________________________________________
+Bool_t AliITSOutStream::CheckCount(ULong_t count)
+{
+  //check boundaries
+  if (count < fStreamLen) return kTRUE;
+  else {
+    Error("CheckCount", "actual size is %d, the necessary size is %d",fStreamLen,count);
+    return kFALSE;
+  }
+}
+
+//____________________________________________________________________________
+void AliITSOutStream::Streamer(TBuffer &R__b){
+  
+  // Stream an object of class AliITSOutStream.
+  
+  static unsigned long *array;
+  static Bool_t make=kTRUE;
+  
+  if (R__b.IsReading()) {
+         R__b >> fStreamLen;
+         //printf("Streamer: fStreamLen %d\n",fStreamLen);
+          if (make) array=new unsigned long[fStreamLen];
+          make=kFALSE;
+          memset(array,0,sizeof(ULong_t)*fStreamLen);
+          fOutStream=array;
+         R__b.ReadFastArray(fOutStream,fStreamLen);
+         
+  } else {
+    R__b << fStreamLen;
+    R__b.WriteFastArray(fOutStream,fStreamLen);
+  }
+}
+
diff --git a/ITS/AliITSRawData.h b/ITS/AliITSRawData.h
new file mode 100644 (file)
index 0000000..c07541c
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef ALIITSRAWDATA_H
+#define ALIITSRAWDATA_H
+
+////////////////////////////////////////////////
+//  RawData classes for set:ITS               //
+////////////////////////////////////////////////
+
+#include <TObject.h>
+
+
+
+class AliITSRawData: public TObject  {
+
+  // most probably it should have a class AliITSHeaderEvent as data member
+   
+ public:
+    AliITSRawData() {
+      // constructor
+    }
+    virtual   ~AliITSRawData() {
+      // destructor
+    }
+
+    ClassDef(AliITSRawData,1)     //RawData object for set:ITS
+
+};
+
+//___________________________________________
+class AliITSInStream: public TObject{
+
+ public:
+  AliITSInStream();
+  AliITSInStream(ULong_t length);
+  virtual   ~AliITSInStream();
+  AliITSInStream(const AliITSInStream &source); // copy constructor
+  AliITSInStream& operator=(const AliITSInStream &source); // ass. operator
+    
+  void ClearStream();
+  Bool_t CheckCount(ULong_t count);
+  ULong_t  StreamLength() {
+    // stream length
+    return fStreamLen;
+  }
+  UChar_t *Stream() {
+    // stream
+    return fInStream;
+  }
+  
+protected:
+  
+  // input stream of unsigned chars
+  
+  ULong_t     fStreamLen;       // Length of the array
+  UChar_t    *fInStream;        // Pointer to an array of input unsigned chararacters
+  
+  
+  
+  ClassDef(AliITSInStream,1)     //Input Stream  object for set:ITS
+    };
+
+//___________________________________________
+class AliITSOutStream: public TObject{
+  
+public:
+  AliITSOutStream();
+  
+  AliITSOutStream(ULong_t length);
+  virtual   ~AliITSOutStream();
+  AliITSOutStream(const AliITSOutStream &source); // copy constructor
+  AliITSOutStream& operator=(const AliITSOutStream &source); // assignment operator
+    
+  void ClearStream();
+  Bool_t CheckCount(ULong_t count);
+  ULong_t  StreamLength() {
+    // stream length
+    return fStreamLen;
+  }
+  ULong_t *Stream() {
+    // stream
+    return fOutStream;
+  }
+  
+protected:
+  
+  // output stream of unsigned chars
+  
+  ULong_t     fStreamLen;        // Length of the array
+  ULong_t    *fOutStream;        // Pointer to an array of unsigned long
+  
+  
+
+    ClassDef(AliITSOutStream,1)     //Output Stream  object for set:ITS
+};
+
+
+
+#endif
diff --git a/ITS/AliITSRecPoint.h b/ITS/AliITSRecPoint.h
new file mode 100644 (file)
index 0000000..0cccf1b
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef ALIITSRECPOINT_H
+#define ALIITSRECPOINT_H 
+
+////////////////////////////////////////////////////
+//  Reconstructed space point class for set:ITS   //
+////////////////////////////////////////////////////
+
+#include <TObject.h>
+
+
+class AliITSRecPoint : public TObject {
+
+
+ public:
+
+  AliITSRecPoint() {
+    // default creator
+    fTracks[0]=fTracks[1]=fTracks[2]=-3; 
+    fX=fZ=fQ=fdEdX=0.;
+    fSigmaX2=fSigmaZ2=0.;
+    fProbability=0;
+   }
+
+  virtual ~AliITSRecPoint() {}; // distructor
+  Bool_t IsSortable() const {return kTRUE;} // allows for sorting
+  Int_t * GetTracks() {return fTracks;} // returns pointer to tracks
+  Float_t GetX(){return fX;} // gets fX
+  Float_t GetZ(){return fZ;} // gets fZ
+  Float_t GetQ(){return fQ;} // gets fQ
+  Float_t GetdEdX(){return fdEdX;} // gets fdEdX
+  Float_t GetSigmaX2(){return fSigmaX2;} // gets fSigmaX2
+  Float_t GetSigmaZ2(){return fSigmaZ2;} // gets fSigmaZ2
+  Float_t GetProbability(){return fProbability;} // gets fProbability
+  void SetX(Float_t x){fX=x;} // sets fX
+  void SetZ(Float_t z){fZ=z;} // sets fZ
+  void SetQ(Float_t q){fQ=q;} // sets fQ
+  void SetdEdX(Float_t dedx){fdEdX=dedx;} // sets fdEdX
+  void SetSigmaX2(Float_t sx2){fSigmaX2=sx2;} // sets fSigmaX2
+  void SetSigmaZ2(Float_t sz2){fSigmaZ2=sz2;} // sets fSigmaZ2
+  void SetProbability(Float_t p){fProbability = p;} // sets fProbability
+  void  Use() {
+    //if fQ<0 cluster is already associated with a track
+    fQ=-fQ;
+  }
+  Int_t IsUsed() const {return (fQ<0) ? 1 : 0;} // checks Use condision
+  Int_t Compare(TObject *o) {
+    //to be defined
+    return 0;
+  } 
+
+ public:
+    Int_t     fTracks[3]; //labels of overlapped tracks
+    Float_t   fX ;        //X of cluster
+    Float_t   fZ ;        //Z of cluster
+    Float_t   fQ ;        //Q of cluster (in ADC counts)
+    Float_t   fdEdX;      //dE/dX inside this cluster
+    Float_t   fSigmaX2;   //Sigma X square of cluster
+    Float_t   fSigmaZ2;   //Sigma Z square of cluster
+
+    Float_t   fProbability; // only temporary solution! - The probability 
+                            // that this is a "real" point in SSD 
+
+  ClassDef(AliITSRecPoint,1)  // AliITSRecPoint class
+};
+
+#endif
+
+
+
diff --git a/ITS/AliITSclusterSSD.cxx b/ITS/AliITSclusterSSD.cxx
new file mode 100644 (file)
index 0000000..150d328
--- /dev/null
@@ -0,0 +1,389 @@
+#include <iostream.h>
+
+#include "AliITSclusterSSD.h"
+
+ClassImp(AliITSclusterSSD)
+
+AliITSclusterSSD::AliITSclusterSSD()
+{
+  // default constructor
+       fSide        = true;
+       fDigits      = 0;
+       fNDigits     = 0;
+       fDigitsIndex = 0;
+        fNCrosses    = 0;
+       fTotalSignal = -1;
+       fNTrack      = -1;
+       fLeftNeighbour  = kFALSE;
+       fRightNeighbour = kFALSE;
+       fCrossedClusterIndexes = new TArrayI(300);
+       fConsumed=kFALSE;
+
+}
+/*************************************************************************/
+
+AliITSclusterSSD::AliITSclusterSSD
+  (Int_t ndigits, Int_t *DigitIndexes, 
+   TObjArray *Digits, Bool_t side)
+{
+  // comment to be written
+       fNDigits = ndigits;
+       fDigits = Digits;
+       fSide = side;
+       fDigitsIndex = new TArrayI(fNDigits,DigitIndexes );     
+       fNCrosses    = 0;
+       fCrossedClusterIndexes = new TArrayI(300);
+       fLeftNeighbour  = kFALSE;
+       fRightNeighbour = kFALSE;
+       fTotalSignal =-1;
+       fNTrack      = -1;
+        fConsumed=kFALSE;
+}
+/*************************************************************************/
+AliITSclusterSSD::~AliITSclusterSSD()
+{
+  // destructor
+  delete fDigitsIndex;
+  delete fCrossedClusterIndexes;
+}
+/*************************************************************************/
+AliITSclusterSSD::AliITSclusterSSD(const AliITSclusterSSD &OneSCluster)
+{
+  // copy constructor
+  if (this == &OneSCluster) return;
+  fNDigits = OneSCluster.fNDigits;
+  fSide=OneSCluster.fSide;
+  fDigits=OneSCluster.fDigits;
+  fDigitsIndex = new TArrayI(fNDigits);
+  fLeftNeighbour  = OneSCluster.fLeftNeighbour;
+  fRightNeighbour = OneSCluster.fRightNeighbour;
+  fTotalSignal =-1;
+  fNTrack      = -1;
+  fNCrosses = OneSCluster.fNCrosses;
+  fConsumed = OneSCluster.fConsumed;
+  Int_t i;
+  for(i = 0; i< fNCrosses ; i++)
+   {
+     fCrossedClusterIndexes[i] = OneSCluster.fCrossedClusterIndexes[i];
+   }
+  for(i = 0; i< fNDigits ; i++)
+  {
+    fDigitsIndex[i]=OneSCluster.fDigitsIndex[i];
+  }
+  return;
+}      
+
+/*************************************************************************/
+AliITSclusterSSD& AliITSclusterSSD::operator=(const AliITSclusterSSD & OneSCluster)
+{
+  // assignment operator
+  if (this == &OneSCluster) return *this;
+  fNDigits = OneSCluster.fNDigits;
+  fSide=OneSCluster.fSide;
+  fDigits=OneSCluster.fDigits;
+  fDigitsIndex = new TArrayI(fNDigits);
+  fLeftNeighbour  = OneSCluster.fLeftNeighbour;
+  fRightNeighbour = OneSCluster.fRightNeighbour;
+  fTotalSignal =-1;
+  fNTrack      = -1;
+  fNCrosses = OneSCluster.fNCrosses;
+  fConsumed = OneSCluster.fConsumed;
+  Int_t i;
+  for(i = 0; i< fNCrosses ; i++)
+   {
+     fCrossedClusterIndexes[i] = OneSCluster.fCrossedClusterIndexes[i];
+   }
+  for(i = 0; i< fNDigits ; i++)
+  {
+    fDigitsIndex[i]=OneSCluster.fDigitsIndex[i];
+  }
+  return *this;
+}      
+
+/*************************************************************************/
+Int_t AliITSclusterSSD::SplitCluster(Int_t where, Int_t *outdigits)
+{
+//This methods generate data necessery to make new object of this class
+//I choosen this way, because methods TClonesArray::Add* dont work
+//so I have to use constraction: new (a[i]) Creator(params...);
+//where 'a' is a TClonesArray 
+//This method generate params - see AliITSmoduleSSD::SplitCluster;
+               
+       
+  Int_t tmp = fNDigits;
+  Int_t ind = 0;
+    outdigits[ind++]=(*fDigitsIndex)[where];
+                     //coping border strip (it is shared by this two clusters)
+    Int_t i;
+    for(i = (where+1); i < tmp; i++)
+     {
+       outdigits[ind++]=(*fDigitsIndex)[i];  //"moving" strips from this to the new one 
+       (*fDigitsIndex)[i]=-1;   
+       fNDigits--;   //deleting strips from this cluster
+     } 
+  return ind;          
+}
+               
+/*******************************************************************/
+Int_t AliITSclusterSSD::GetDigitStripNo(Int_t digit)
+{
+  // comment to be written
+       if (digit<0) return -1;
+       return (digit>(fNDigits-1))?-1 :
+            ((AliITSdigitSSD*)((*fDigits)[(*fDigitsIndex)[digit]]))->GetStripNumber();
+}
+/************************************************************/
+Int_t AliITSclusterSSD::GetDigitSignal(Int_t digit)
+{
+  Int_t index,signal;
+  // returns digit signal
+  if (digit<0||digit>=fNDigits) return -1;
+  index  = (*fDigitsIndex)[digit];
+  signal = ((AliITSdigitSSD*)((*fDigits)[index]))->GetSignal();
+  /*
+  if(signal>1.e5) printf("GetDigitSignal: digit %d index %d signal %d\n",
+                        digit,index, signal);
+  */
+  return  signal;
+}
+
+/***********************************************************/
+void  AliITSclusterSSD::AddCross(Int_t clIndex)
+{
+  // comment to be written
+       (*fCrossedClusterIndexes)[fNCrosses++] = clIndex;
+}
+/***********************************************************/
+
+Int_t AliITSclusterSSD::GetCross(Int_t crIndex)
+{
+  // comment to be written
+  return ((crIndex>-1)&&(crIndex<fNCrosses))?(*fCrossedClusterIndexes)[crIndex]:-1;
+}
+/***********************************************************/
+Double_t AliITSclusterSSD::CentrOfGravity()
+{
+  // comment to be written
+  Float_t ret=0;
+  
+  if (fLeftNeighbour) ret+=(GetDigitStripNo(0)*0.5*GetDigitSignal(0));
+      else ret+=(GetDigitStripNo(0)*GetDigitSignal(0));
+  
+  if (fRightNeighbour) ret+=(GetDigitStripNo(fNDigits -1)*0.5*GetDigitSignal(fNDigits -1));
+      else ret+=(GetDigitStripNo(fNDigits -1)*GetDigitSignal(fNDigits-1));
+  Int_t i;
+  for(i=1;i<fNDigits-1;i++)
+    {
+      ret +=GetDigitStripNo(i)*GetDigitSignal(i);
+    }
+  
+  if (fTotalSignal<0) GetTotalSignal();
+       
+    return (ret/fTotalSignal);
+}
+
+/***********************************************************/
+Float_t AliITSclusterSSD::GetTotalSignal()
+{
+  // comment to be written
+  if(fTotalSignal <0)
+    {
+      fTotalSignal=0;
+      if (fNDigits ==1)  {
+          fTotalSignal = (Float_t)GetDigitSignal(0);
+         //printf("1 digit: signal %d \n",GetDigitSignal(0)); 
+         return fTotalSignal;
+      }
+
+      if (fLeftNeighbour) fTotalSignal += (Float_t)(0.5*GetDigitSignal(0));
+      else fTotalSignal += (Float_t) GetDigitSignal(0);
+      //printf("GetTotalSignal :i  DigitSignal %d %d \n",0,GetDigitSignal(0)); 
+               
+      if (fRightNeighbour) fTotalSignal += (Float_t)(0.5*GetDigitSignal(fNDigits -1));
+      else fTotalSignal += (Float_t)GetDigitSignal(fNDigits-1);
+      //printf("GetTotalSignal :i  DigitSignal %d %d \n",fNDigits -1,GetDigitSignal(fNDigits -1)); 
+      Int_t i;         
+      for(i = 1;i<fNDigits -1;i++) 
+        {
+         fTotalSignal += (Float_t)GetDigitSignal(i);
+         //printf("GetTotalSignal :i  DigitSignal %d %d \n",i,GetDigitSignal(i)); 
+       }
+      //printf("GetTotalSignal: fNDigits %d fTotalSignal %.0f \n",fNDigits,fTotalSignal); 
+    }
+   return fTotalSignal;
+}
+/***********************************************************/
+
+Float_t  AliITSclusterSSD::GetTotalSignalError()
+{
+  // comment to be written
+  Float_t err =0;
+  Int_t i;
+  for(i =1; i<fNDigits -1; i++)
+    {
+      err+=0.1*GetDigitSignal(i);   
+    } 
+  if (GetLeftNeighbour())
+   {
+    err+=GetDigitSignal(0);
+   }
+  else
+   {
+    err+=0.1*GetDigitSignal(0);
+   } 
+  if (GetRightNeighbour())
+   {
+    err+=GetDigitSignal(fNDigits -1);
+   }
+  else
+   {
+    err+=0.1*GetDigitSignal(fNDigits -1);
+   }
+  return err; 
+   
+}
+
+/***********************************************************/
+
+void AliITSclusterSSD::DelCross(Int_t index)
+{
+  // comment to be written
+Int_t i,j; //iterators
+
+for(i =0;i<fNCrosses;i++)
+ {
+  if ((*fCrossedClusterIndexes)[i] == index)
+   {
+     for(j=i;j<fNCrosses-1;j++)
+      {
+        (*fCrossedClusterIndexes)[j]=(*fCrossedClusterIndexes)[j+1];
+      }
+     fNCrosses--;
+     return; 
+   }
+ }
+
+}
+/***********************************************************/
+
+Int_t  *AliITSclusterSSD::GetTracks(Int_t &nt)
+{
+  // comment to be written
+  Int_t *tidx=0;
+  Int_t i, bit;
+  nt=0;
+
+  
+   
+   fNTrack =0;
+   for(i=0;i<10;i++)
+    {
+     fTrack[i] = 0;
+    }
+   
+   tidx=GetDigit(0)->GetTracks();
+        
+   for(i = 0; i<3;i++)
+   {
+    fTrack[i]=tidx[i];
+    if (fTrack[i] != 0) fNTrack++;
+   }
+   for(i = 1; i<fNDigits; i++)
+   {
+    tidx=GetDigit(i)->GetTracks();
+    Int_t j;
+    for(j = 0; j<3;j++)
+    {
+     bit = 1;
+     if (tidx[j]==0) break;
+     Int_t k;
+     for(k = 0; k < fNTrack;k++)
+      {
+       if (tidx[j]==fTrack[k]) bit =0;
+      }
+     if (bit) fTrack[fNTrack++]=tidx[j];       
+    }
+   }
+       
+  if (fNTrack > 10)
+   {
+     cout<<"\n\n Error AliITSclusterSSD::GetTracks  OUT  "<<fNDigits<<"   "<<fNTrack<<"\n\n\n\n\n";
+     
+   }
+
+ nt = fNTrack;
+ if(!nt) return 0;
+ return &(fTrack[0]);
+}
+/***********************************************************/
+
+Double_t AliITSclusterSSD::GetPosition()
+{
+  // comment to be written
+  Float_t ret;
+  switch(fNDigits)
+   {
+     case  1:
+       ret = GetDigitStripNo(0);
+       break;
+     case  2:
+       ret = EtaAlgorithm();
+       break;       
+     default:
+       ret = CentrOfGravity();   
+   }
+  return ret;
+}
+
+/***********************************************************/
+
+Double_t AliITSclusterSSD::EtaAlgorithm()
+{
+  // comment to be written
+  if (fNDigits != 2) return -1;
+
+  Int_t strip1  = GetDigit(0)->GetStripNumber(); 
+  Int_t strip2  = GetDigit(1)->GetStripNumber();
+  Int_t signal1 = GetDigit(0)->GetSignal();
+  Int_t signal2 = GetDigit(1)->GetSignal();
+
+  Double_t eta;
+  
+  if (strip1<strip2)
+   {
+    eta = ((Double_t)signal2)/((Double_t)(signal1+signal2));
+    if (eta<0.04) return strip1;
+    if (eta>0.96) return strip2;
+    return (strip1 + 0.43478261*eta + 0.2826087);   
+   }
+  else
+  {
+    eta = ((Double_t)signal1)/((Double_t)(signal1+signal2));
+    if (eta<0.04) return strip2;
+    if (eta>0.96) return strip1;
+    return (strip2 + 0.43478261*eta + 0.2826087);   
+  }
+
+}
+
+Double_t  AliITSclusterSSD::GetPositionError()
+{
+  // comment to be written
+ return (GetNumOfDigits()+1)/2;
+}
+
+Bool_t AliITSclusterSSD::IsCrossingWith(Int_t idx)
+{
+  // comment to be written
+ Int_t i;
+ for(i =0; i< fNCrosses;i++)
+  {
+    if (GetCross(i) == idx) return kTRUE;
+  }
+ return kFALSE;
+}
diff --git a/ITS/AliITSclusterSSD.h b/ITS/AliITSclusterSSD.h
new file mode 100644 (file)
index 0000000..8ac723d
--- /dev/null
@@ -0,0 +1,154 @@
+#ifndef ALIITSCLUSTERSSD_H
+#define ALIITSCLUSTERSSD_H
+
+#include "TObject.h"
+#include "TArrayI.h"
+#include "AliITSdigit.h"
+#include "TClonesArray.h"
+
+
+class AliITSclusterSSD : public TObject
+{
+
+
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+//
+// Describes set of neighbouring digits on one side of detector,
+// that are supposed to be generated by one particle.
+// includes information about clusters on other side that it crosses with
+
+public:
+
+  AliITSclusterSSD();    //Default Constructor
+  ~AliITSclusterSSD();
+  AliITSclusterSSD(Int_t ndigits, Int_t *DigitIndexes, TObjArray *Digits, Bool_t side);                
+  AliITSclusterSSD(const AliITSclusterSSD &source); 
+  AliITSclusterSSD&  operator=( const AliITSclusterSSD & source);
+               
+  void            AddDigit(Int_t index){
+                                       // //adds on digit
+                                       (*fDigitsIndex)[fNDigits++]=index;
+                                       } 
+  TObjArray*      GetPointer2Digits(){
+                                     // comment to be written 
+                                     return fDigits;
+                                     }
+
+//  TArrayI*        GetDigitsIndexes(Int_t &ndigits);  
+//  void            SetDigitIndex(Int_t index);
+
+  void            SetPointer2Digits(TObjArray *digits){
+                                                      // comment to be written
+                                                      fDigits = digits;
+                                                      }
+  Int_t           GetNumOfDigits(){
+                                  //Returns number of digits that creates this cluster
+                                  return fNDigits;
+                                  }
+  Int_t           GetDigitSignal(Int_t digit);      
+
+  
+  AliITSdigitSSD *GetDigit(Int_t idx) {
+                                      // comment to be written
+                                      return (AliITSdigitSSD *)((*fDigits)[GetDigitIndex(idx)]);
+                                      }
+  Int_t           GetDigitIndex (Int_t digit) {
+                                              // comment to be written
+                                              return (*fDigitsIndex)[digit];
+                                              }
+  Int_t           GetDigitStripNo(Int_t digit);
+  Int_t           GetFirstDigitStripNo(){
+                                        // comment to be written
+                                        return GetDigitStripNo(0);
+                                        }
+  Int_t           GetLastDigitStripNo(){
+                                       // comment to be written
+                                       return GetDigitStripNo(fNDigits-1);
+                                       }
+  Int_t           SplitCluster(Int_t where,Int_t *outdigits); //splits this one side cluster for two
+  void            AddCross(Int_t clIndex);  //Add index of cluster that it crosses with
+  Int_t           GetCross(Int_t crIndex);  //return index of cluster that it crosses with
+  Int_t           GetCrossNo() {
+                               // Returns number of crosses
+                               return fNCrosses;
+                               } 
+  void            DelCross(Int_t index);
+  
+  Double_t        GetPosition();
+  Double_t        GetPositionError();
+  Float_t         GetTotalSignal();  
+  Float_t         GetTotalSignalError();
+  void            CutTotalSignal(Float_t sx) {
+    // comment to be written
+    if (fTotalSignal>sx) fTotalSignal-=sx;
+  }
+  
+  Bool_t         GetRightNeighbour() const {
+                                            // comment to be written
+                                            return fRightNeighbour;
+                                            }
+  Bool_t         GetLeftNeighbour() const {
+                                           // comment to be written
+                                           return fLeftNeighbour;
+                                           }
+  void           SetRightNeighbour(Bool_t nei) {
+                                           // comment to be written
+                                           fRightNeighbour=nei;
+                                           }
+  void           SetLeftNeighbour(Bool_t nei) {
+                                           // comment to be written
+                                           fLeftNeighbour=nei;
+                                           }
+  Bool_t          GetSide(){
+                           // comment to be written
+                           return fSide;
+                           }
+  Int_t           CheckSatus(Int_t *tracks){
+                                           //check if digits comes from the same track
+                                           return 0;
+                                           }  
+  Int_t          *GetTracks(Int_t &nt);
+  void            Consume(){
+                           // comment
+                           fConsumed = kTRUE;
+                           }
+  Bool_t          IsConsumed() const{ 
+                                    // comment
+                                    return fConsumed;
+                                    }
+  Bool_t          IsCrossingWith(Int_t idx);
+  
+protected:
+
+  Bool_t          fSide;           //True if P
+  TObjArray      *fDigits;         //Pointer to List of Digitsbelonging to AliITS
+               
+  Int_t           fNDigits;        //Number of digits that make up that cluster 
+  TArrayI        *fDigitsIndex;    // Digit indexes in fDigits array
+               
+  Int_t           fNCrosses;       //Number of crossed one side clusters on the other siede 
+                                   //   (max 8 : it is not aribtrary)
+  TArrayI        *fCrossedClusterIndexes; //Array of inedexes of crossed clusters (in TClonesArray)
+                                          // not in TArrayI in package
+
+  Bool_t          fLeftNeighbour;   // comment to be written
+  Bool_t          fRightNeighbour;  // comment to be written 
+  Bool_t          fConsumed;        // comment to be written
+  
+  Float_t         fTotalSignal;     // comment to be written
+  Int_t           fTrack[10];       // comment to be written
+  Int_t           fNTrack;          // comment to be written
+
+  Double_t        CentrOfGravity();
+  Double_t        EtaAlgorithm();
+
+private:
+                                                               
+/*************************************/
+/*************************************/                                                
+  ClassDef(AliITSclusterSSD,1)
+};
+
+#endif
diff --git a/ITS/AliITSdcsSSD.cxx b/ITS/AliITSdcsSSD.cxx
new file mode 100644 (file)
index 0000000..14d898b
--- /dev/null
@@ -0,0 +1,217 @@
+
+#include "AliITSdcsSSD.h"
+#include "AliITSresponseSSD.h"
+#include "AliITSsegmentationSSD.h"
+
+ClassImp(AliITSdcsSSD)
+
+
+//_____________________________________________________________________
+//
+// Constructor and Destructor
+//_____________________________________________________________________
+
+
+AliITSdcsSSD::AliITSdcsSSD(AliITSsegmentation *seg, AliITSresponse *resp) 
+{
+  // constructor
+
+    fRandom = new TRandom();
+
+    fNstrips = seg->Npx();
+    
+    fInvalidP = new TArrayS();
+    fInvalidN = new TArrayS();
+
+    Int_t npar=resp->NDetParam();
+    if (npar < 6) {
+       Warning("AliITSdcsSSD","I need 6 parameters ");
+       npar=6;
+    }
+
+    Float_t detpar[npar];
+    resp->GetDetParam(detpar);
+
+    fNInvalid = detpar[0];
+    fISigma = detpar[1];
+
+    fCouplingPR = detpar[2];
+    fCouplingPL = detpar[3];
+    fCouplingNR = detpar[4];
+    fCouplingNL = detpar[5]; 
+
+
+    Option_t *opt,*dummy;
+    resp->ParamOptions(opt,dummy);
+    if (strstr(opt,"SetInvalid")) SetInvalidMC(fNInvalid,fISigma);
+
+}
+
+//_____________________________________________________________________
+
+
+AliITSdcsSSD::~AliITSdcsSSD() {
+  // destructor
+    delete fInvalidP;
+    delete fInvalidN;
+}
+
+//__________________________________________________________________________
+AliITSdcsSSD::AliITSdcsSSD(const AliITSdcsSSD &source){
+  //     Copy Constructor 
+  if(&source == this) return;
+  this->fCouplingPR = source.fCouplingPR;
+  this->fCouplingPL = source.fCouplingPL;
+  this->fCouplingNR = source.fCouplingNR;
+  this->fCouplingNL = source.fCouplingNL;
+  this->fNstrips = source.fNstrips;
+  this->fNInvalid = source.fNInvalid;
+  this->fISigma = source.fISigma;
+  this->fInvalidP = source.fInvalidP;
+  this->fInvalidN = source.fInvalidN;
+  this->fRandom = source.fRandom;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSdcsSSD& 
+  AliITSdcsSSD::operator=(const AliITSdcsSSD &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fCouplingPR = source.fCouplingPR;
+  this->fCouplingPL = source.fCouplingPL;
+  this->fCouplingNR = source.fCouplingNR;
+  this->fCouplingNL = source.fCouplingNL;
+  this->fNstrips = source.fNstrips;
+  this->fNInvalid = source.fNInvalid;
+  this->fISigma = source.fISigma;
+  this->fInvalidP = source.fInvalidP;
+  this->fInvalidN = source.fInvalidN;
+  this->fRandom = source.fRandom;
+  return *this;
+}
+
+//_____________________________________________________________________
+//
+//  Methods for creating invalid strips
+//_____________________________________________________________________
+//
+
+
+void AliITSdcsSSD::SetInvalidMC(Float_t mean, Float_t sigma) {
+  // set invalid MC
+    SetInvalidParam(mean, sigma);
+    SetInvalidMC();
+}
+
+//_____________________________________________________________________
+
+void AliITSdcsSSD::SetInvalidMC() {
+  // set invalid MC
+    Int_t pside;
+    Int_t nside;
+    Int_t i;
+    Int_t strip;
+
+    pside = (Int_t)fRandom->Gaus(fNInvalid, fISigma);
+    nside = (Int_t)fRandom->Gaus(fNInvalid, fISigma);
+    
+    fInvalidP->Set(pside);
+    fInvalidN->Set(nside);
+     
+    for(i=0 ;i<pside; i++) {
+       strip = (Int_t)(fRandom->Rndm() * fNstrips);
+       fInvalidP->AddAt(strip, i); 
+    }
+    
+    for(i=0 ;i<nside; i++) {
+       strip = (Int_t)(fRandom->Rndm() * fNstrips);
+       fInvalidN->AddAt(strip, i); 
+    }  
+}
+
+//_____________________________________________________________________
+
+
+void AliITSdcsSSD::SetInvalidParam(Float_t mean, Float_t sigma) {
+  // set invalid param
+    fNInvalid = mean;
+    fISigma = sigma;
+
+    fNInvalid = (fNInvalid<0)? 0 : fNInvalid;
+    fNInvalid = (fNInvalid>fNstrips)? fNstrips: fNInvalid;
+    
+    fISigma = (fISigma < 0)? 0 : fISigma;
+    fISigma = (fISigma > fNstrips/10) ? fNstrips/10 : fISigma;
+}
+
+
+//_____________________________________________________________________
+
+
+void AliITSdcsSSD::GetInvalidParam(Float_t &mean, Float_t &sigma) {
+  // get invalid param
+    mean = fNInvalid;
+    sigma = fISigma;
+
+}
+
+
+//_____________________________________________________________________
+//
+//  Methods for accessing to invalid strips
+//_____________________________________________________________________
+//
+
+
+Bool_t AliITSdcsSSD::IsValidP(Int_t strip) {
+  // isvalidP
+    Int_t nElem = fInvalidP->GetSize();
+    Int_t i;
+    for(i = 0; i<nElem; i++)
+       if(fInvalidP->At(i) == strip) return kFALSE;
+    return kTRUE;
+}
+
+//_____________________________________________________________________
+
+Bool_t AliITSdcsSSD::IsValidN(Int_t strip) {
+  // is valid N
+    Int_t nElem = fInvalidN->GetSize();
+    Int_t i;
+    for(i = 0; i<nElem; i++)
+       if(fInvalidN->At(i) == strip) return kFALSE;
+    return kTRUE;
+}
+
+//_____________________________________________________________________
+
+
+TArrayS* AliITSdcsSSD::GetInvalidP() {
+  // get invalid P
+    return fInvalidP;
+}
+
+TArrayS* AliITSdcsSSD::GetInvalidN() {
+  // get invalid N
+    return fInvalidN;
+}
+
+Int_t AliITSdcsSSD::GetNInvalidP(){
+  // get numeber of invalid P    
+    return fInvalidP->GetSize();
+}
+
+Int_t AliITSdcsSSD::GetNInvalidN() {
+  // // get number of invalid N
+    return fInvalidN->GetSize();
+}
+
+//_____________________________________________________________________
+
+
+
+
+
+
+
diff --git a/ITS/AliITSdcsSSD.h b/ITS/AliITSdcsSSD.h
new file mode 100644 (file)
index 0000000..17bd003
--- /dev/null
@@ -0,0 +1,137 @@
+#ifndef ALIITSDCSSSD_H
+#define ALIITSDCSSSD_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#include <TObject.h>
+#include <TArrayS.h>
+#include <TRandom.h>
+
+//____________________________________________________________________
+//
+//  Class AliITSdcsSSD 
+//  describes Detector Control System parameters for one SSD module.
+//   
+//  This class stores parametrers such as gain, threshold
+//  capacitive coupling.
+//  
+//  Class takes care of invalid strip menagement during 
+//  simulation and runtime
+//
+//
+//  created at: Warsaw University of Technology
+//  ver. 1.0    WARSAW, 23.12.1999  
+// 
+//___________________________________________________________________
+//
+
+
+class AliITSsegmentation;
+class AliITSresponse;
+
+
+class AliITSdcsSSD: public TObject {
+
+public:       
+    
+    //________________________________________________________________
+    //
+    // Constructors and deconstructor
+    //________________________________________________________________
+    //
+    
+    AliITSdcsSSD(AliITSsegmentation *s, AliITSresponse *r);
+    ~AliITSdcsSSD();
+    AliITSdcsSSD(const AliITSdcsSSD &source); // copy constructor
+    AliITSdcsSSD& operator=(const AliITSdcsSSD &source); // assignment operator
+    
+    //________________________________________________________________
+    // 
+    // Invalid strips management methods
+    //________________________________________________________________
+    //
+    
+    // Parameters for invalid strips MonteCarlo
+    
+    void SetInvalidParam(Float_t mean, Float_t sigma);
+    void GetInvalidParam(Float_t &mean, Float_t &sigma); 
+    
+    
+    // Methods for creating invalid strips
+    
+    void SetInvalidMC(Float_t mean, Float_t sigma);
+    void SetInvalidMC();
+    
+    
+    // Testing if strip is valid
+    
+    Bool_t  IsValidN(Int_t strip);      //True if strip works properly
+    Bool_t  IsValidP(Int_t strip);      //True if strip works properly
+    
+    
+    // Access to invalid strips
+    
+    TArrayS *GetInvalidP();             //Array of invalid P strips
+    TArrayS *GetInvalidN();             //Array of invalid N strips
+    Int_t    GetNInvalidP();            //Number of invalid P strips
+    Int_t    GetNInvalidN();            //Number of invalid N strips
+    
+    
+    // Creating invalid strips
+    
+    void    SetInvalidP(Int_t strip, Bool_t side){
+      //Set invalid if true   
+    }
+    
+    void    SetInvalidN(Int_t strip, Bool_t side){
+      //Set invalid if true
+    }
+
+    Float_t  GetCouplingPR() {
+      // couplings
+      return fCouplingPR;
+    }
+
+    Float_t  GetCouplingPL() {
+      // couplings
+      return fCouplingPL;
+    }
+
+    Float_t  GetCouplingNR() {
+      // couplings
+      return fCouplingNR;
+    }
+
+    Float_t  GetCouplingNL() {
+      // couplings
+      return fCouplingNL;
+    }
+    
+ protected:   
+    
+    //_____________________________________________
+    //
+    // Parameters for invalid strips simulatation 
+    //_____________________________________________
+    
+    Float_t  fCouplingPR;  // couplings
+    Float_t  fCouplingPL;  // couplings
+    Float_t  fCouplingNR;  // couplings
+    Float_t  fCouplingNL;  // couplings   
+
+    Float_t   fNstrips ;          //Number of strips
+    Float_t   fNInvalid;          //Mean number of invalid strips (for simulation) 
+    Float_t   fISigma;            //RMS of invalid strips (Gaussian)
+
+    TArrayS  *fInvalidP;          //Array of invalid strips on P-side
+    TArrayS  *fInvalidN;          //Array of invalid strips on N-side
+   
+    TRandom  *fRandom;            //!Random numbers generator
+
+    ClassDef(AliITSdcsSSD, 1)     // ITS SSD DCS specific class
+
+};
+
+
+#endif
diff --git a/ITS/AliITSdictSSD.cxx b/ITS/AliITSdictSSD.cxx
new file mode 100644 (file)
index 0000000..5377d07
--- /dev/null
@@ -0,0 +1,42 @@
+
+#include <stdio.h>
+#include <TObjArray.h>
+
+#include "AliITSsegmentationSSD.h"
+#include "AliITSresponseSSD.h"
+#include "AliITSsimulationSSD.h"
+#include "AliITSdictSSD.h"
+#include "AliITSdcsSSD.h"
+#include "AliITS.h"
+#include "AliRun.h"
+
+
+void AliITSdictSSD::AddTrack(Int_t track) {
+  // add track
+    if (fTracks > 9) return;
+    Int_t exist = 0,i;
+    
+    for(i=0; i<10; i++) 
+     {
+       if(track == fTrack[i]) 
+        {
+        exist = 1;
+       }
+      
+      } 
+    if (!exist) 
+     {
+     fTrack[fTracks++] = track;     
+     }
+
+}
+
+
+Int_t AliITSdictSSD::GetTrack(Int_t index) {
+  // get track
+    if(index > fTracks) return 0;
+    else return fTrack[index];
+}
+
+
+//****************************************************************************
diff --git a/ITS/AliITSdictSSD.h b/ITS/AliITSdictSSD.h
new file mode 100644 (file)
index 0000000..12865cd
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef ALIITSDICTSSD_H
+#define ALIITSDICTSSD_H
+
+#include <TArrayF.h>
+
+#include "AliITSdcsSSD.h"
+
+class AliITSdcsSSD;
+
+class AliITSdictSSD  {
+
+public:
+  
+  AliITSdictSSD() {
+    // constructor
+    fTracks = 0;
+  }
+  ~AliITSdictSSD() {
+    // destructor
+  };
+  
+  void   AddTrack(Int_t track); 
+  Int_t  GetTrack(Int_t index);
+  Int_t  GetNTracks() {
+    // get num of tracks
+    return fTracks;
+  }
+  void   ZeroTracks() { 
+    // zero tracks
+    for (Int_t i =0;i<10;i++) fTrack[i]=0; fTracks = 0;
+  }
+  
+private:           
+  Int_t fTrack[10];    // Track array
+  Int_t fTracks;       // Tracks
+};   
+
+
+#endif
diff --git a/ITS/AliITSetfSDD.cxx b/ITS/AliITSetfSDD.cxx
new file mode 100644 (file)
index 0000000..865c62d
--- /dev/null
@@ -0,0 +1,195 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log$
+Revision 1.1.2.2  2000/06/12 18:09:36  barbera
+fixed posible compilation errors on HP unix
+
+Revision 1.1.2.1  2000/01/12 20:21:30  nilsen
+missed AliITSetfSDD files ealier
+
+$Name$
+$Author$
+$Id$
+*/
+
+#include <iostream.h>
+#include <TMath.h>
+#include "AliITSetfSDD.h"
+
+////////////////////////////////////////////////////////////////////////
+// Version: 0
+// Written by Piergiorgio Cerello
+// November 23 1999
+//
+// AliITSmapSDD is the map of SDDs.
+//
+//Begin_Html
+/*
+<img src="picts/ITS/AliITShit_Class_Diagram.gif">
+</pre>
+<br clear=left>
+<font size=+2 color=red>
+<p>This show the relasionships between the ITS hit class and the rest of Aliroot.
+</font>
+<pre>
+*/
+//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<e; i++) power *= b;
+  return power;
+}
+
+AliITSetfSDD::AliITSetfSDD(Double_t timeclock)
+{
+  // sampling time in ns
+  fSamplingTime = 1000./timeclock;
+  fT0 = 0.;
+  fDf = ppower(10,9)/(fMaxNofSamples*fSamplingTime);
+  fA0 = 9000.;
+
+  Int_t i,j,k;
+  for(i=0; i<fMaxNofPoles; i++) {
+    fZero_M[i] = 0.;
+    fZero_R[i] = 0.;
+    fZero_I[i] = 0.;
+    fPole_M[i] = 0.;
+    fPole_R[i] = 0.;
+    fPole_I[i] = 0.;
+  }
+  fPole_M[0] = 1.;
+  fPole_R[0] = -2100000.;
+  fPole_I[0] = fPole_R[0];
+  fPole_M[1] = 1.;
+  fPole_R[1] = -2100000.;
+  fPole_I[1] = -fPole_R[1];
+
+   // Compute Transfer Function
+
+  Double_t PI = acos(-1.);
+  for(i=0; i<=fMaxNofSamples/2; i++) {
+    Double_t frequency = fDf*i;
+    Double_t VM = fA0;
+    Double_t VA = 0.;
+    for(k=0; k<fMaxNofPoles; k++) {
+      if(fZero_M[k]) {
+        Double_t VZR = -fZero_R[k];
+        Double_t VZI = frequency - fZero_I[k];
+        Double_t VZM = TMath::Sqrt(VZR*VZR+VZI*VZI);
+        Double_t VZA = TMath::ATan2(VZI,VZR);
+       //      cout << "VZM: " << VZM << ", VZA: " << VZA << endl;
+       //      cout << "VZR: " << VZR << ", VZI: " << VZI << endl;
+        for(j=1; j<= (Int_t) fZero_M[k]; j++) {
+          VM *= VZM;
+          VA += VZA;
+          if(VA >= 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<fMaxNofPoles; i++) cout << fZero_M[i] << endl;
+  cout << "fZero_R " << endl;
+  for(i=0; i<fMaxNofPoles; i++) cout << fZero_R[i] << endl;
+  cout << "fZero_I " << endl;
+  for(i=0; i<fMaxNofPoles; i++) cout << fZero_I[i] << endl;
+  cout << "fPole_M " << endl;
+  for(i=0; i<fMaxNofPoles; i++) cout << fPole_M[i] << endl;
+  cout << "fPole_R " << endl;
+  for(i=0; i<fMaxNofPoles; i++) cout << fPole_R[i] << endl;
+  cout << "fPole_I " << endl;
+  for(i=0; i<fMaxNofPoles; i++) cout << fPole_I[i] << endl;
+
+  cout << "Transfer function" << endl;
+  cout << "Real Part" << endl;
+  for(i=0; i<fMaxNofSamples; i++) cout << fTf_R[i] << endl;
+  cout << "Imaginary Part " << endl;
+  for(i=0; i<fMaxNofSamples; i++) cout << fTf_I[i] << endl;
+
+  cout << "Fourier Weights" << endl;
+  cout << "Real Part" << endl;
+  for(i=0; i<fMaxNofSamples; i++) cout << fW_R[i] << endl;
+  cout << "Imaginary Part " << endl;
+  for(i=0; i<fMaxNofSamples; i++) cout << fW_I[i] << endl;
+}
+
+
+
+
+
+
+
+
diff --git a/ITS/AliITSetfSDD.h b/ITS/AliITSetfSDD.h
new file mode 100644 (file)
index 0000000..5c618ac
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef ITSETFSDD_H
+#define ITSETFSDD_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#include <TObject.h>
+
+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 (file)
index 0000000..5c36f8f
--- /dev/null
@@ -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<fNclustersN;i++)
+    {
+      fClusterNIndexes[i]= package.fClusterNIndexes[i]; 
+    }
+  
+  for(i =0; i<fNclustersP;i++)
+    {
+      fClusterPIndexes[i]= package.fClusterPIndexes[i]; 
+    }
+  
+  if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
+  
+  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<fNclustersN;i++)
+  {
+    fClusterNIndexes[i]= package.fClusterNIndexes[i]; 
+  }
+
+for(i =0; i<fNclustersP;i++)
+  {
+    fClusterPIndexes[i]= package.fClusterPIndexes[i]; 
+  }
+
+if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
+
+return *this; 
+  
+}
+
+
+/*******************************************************/
+
+Int_t 
+AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
+
+{
+  if ((index>-1)&&(index<fNclustersN))
+    return (*fClusterNIndexes)[index];
+  else 
+   {
+    cout << "AliITSpackageSSD::GetNSideClusterIdx  : Out of Range\n";
+    return -1;
+   }
+}
+/*******************************************************/
+
+
+Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
+{
+  if ((index>-1)&&(index<fNclustersP))
+    return (*fClusterPIndexes)[index];
+  else 
+  {
+  cout << "AliITSpackageSSD::GetPSideClusterIdx  : Out of Range\n";
+   return -1;
+  } 
+}
+/*******************************************************/
+AliITSclusterSSD*  
+AliITSpackageSSD::GetPSideCluster(Int_t index)
+{
+
+return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
+}
+
+/*******************************************************/
+
+AliITSclusterSSD*  
+AliITSpackageSSD::GetNSideCluster(Int_t index)
+{
+return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
+}
+
+
+/*******************************************************/
+
+
+
+Bool_t 
+AliITSpackageSSD::GetClusterWithOneCross
+  (Int_t & index, Bool_t& side)
+{
+  
+ if((fNclustersP==0)||(fNclustersN==0) )
+  {
+    printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
+    index = -2;
+    return kFALSE;
+  } 
+ Int_t ind;
+
+ ind =(*fClusterPIndexes)[fNclustersP-1]; 
+ if (  ( ((AliITSclusterSSD*)(*fClustersP)[ind]  )->GetCrossNo()  ) ==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;i<ncr;i++)
+   {
+    idx = clToDel->GetCross(i);
+    ((AliITSclusterSSD *)((*fClustersN)[idx])   )->DelCross(clToDelIdx);
+   }
+ for(i=index;i<fNclustersP-1;i++)
+  {
+       (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
+  }
+ fNclustersP--; 
+ if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
+
+
+ for(i=0;i<fNclustersN;i++)
+  {
+    if ( (GetNSideCluster(i)->GetCrossNo())==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;i<ncr;i++)
+   {
+    idx = clToDel->GetCross(i);
+    ((AliITSclusterSSD *)((*fClustersP)[idx])   )->DelCross(clToDelIdx);
+   }
+ for(i=index;i<fNclustersN-1;i++)
+  {
+       (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
+  }
+ fNclustersN--; 
+ if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
+
+ for(i=0;i<fNclustersP;i++)
+  {
+    if ( (GetPSideCluster(i)->GetCrossNo())==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;i<fNclustersP-1;i++)
+       {
+         if( ((*fClusterPIndexes)[i])==index)
+         {
+            DelPCluster(i);
+            return;
+         }
+       }
+    }
+  }
+ cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
+
+}
+
+
+/*******************************************************/
+
+void AliITSpackageSSD::DelNClusterOI(Int_t index)
+{
+//This function looks like this, 
+//because probably cluster to cut is 
+//on the beginning or on the end of package 
+
+ Int_t i;
+ if( ((*fClusterNIndexes)[0])==index) 
+  {
+    DelNCluster(0);
+    return;
+  }
+ else
+  { 
+   if( ((*fClusterNIndexes)[fNclustersN-1])==index)
+    {
+      DelNCluster(fNclustersN-1);
+      return;
+    }
+   else
+    {
+     for(i=1;i<fNclustersN-1;i++)
+       {
+         if( ((*fClusterNIndexes)[i])==index)
+         {
+          DelNCluster(i);
+          return;
+         }
+       }
+    }
+  }
+ cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
+}
+
+
+/*******************************************************/
+
+
+void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
+{
+ if (side == SIDEP)
+  {    
+    DelPClusterOI(index);
+  } 
+  else
+  {
+    DelNClusterOI(index);
+  }
+
+}
+
+
+/**********************************************/
+
+
+void  AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
+{
+  
+  Int_t *takenNcl = new Int_t[fNclustersN];
+  
+  num=0;
+  
+  if (debug) PrintClusters();
+
+  Int_t i;
+  for(i=0;i<fNclustersP;i++)
+   {
+     takenNcl[i]=-1;
+   }
+  //see comment on the beginning of MakeCombin
+  if (debug) cout<<"GetAllCombinations entered";
+  MakeCombin (array,num,0,takenNcl,sizet);
+
+  delete []takenNcl; 
+}
+/**********************************************/
+
+
+void  AliITSpackageSSD::MakeCombin
+   (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
+
+{
+
+//ATTENTION: anybody watching this function
+//AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
+//however, we have pointer to that array (TClonesArray)
+//we can not use 
+//Get?SideCluster because it takes index from local look_up_table
+ Int_t i,j;
+ //this cluster
+ AliITSclusterSSD *cl=GetPSideCluster(np);
+
+ //printf("np %d cl %p\n",np,cl);
+
+ Int_t NC = cl->GetCrossNo();  //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;i<NC;i++) {
+     indcro=cl->GetCross(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;j<fNclustersP;j++)  
+        {
+         //printf("if- for: j nu occup[j] %d %d %d\n",j, nu, occup[j]);
+          if (nu<sizet) arr[nu][j]=occup[j];
+          else {
+            //printf("MakeComb - exceeding array size! i j %d %d\n",i,j);
+              continue;}
+          //printf("if- for: j nu arr[nu][j] %d %d %d\n",j, nu, arr[nu][j]);
+           
+        }
+      
+        occup[np]=-1;
+        if (nu<sizet-1) nu++;
+       //printf("i j nu %d %d %d \n",i,j,nu);
+     }
+   }
+  } else {
+    // printf("else \n");
+
+    for(i=0;i<NC;i++) {
+       indcro=cl->GetCross(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 (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
+         //else printf("MakeComb - exceeding array size!\n");
+       }
+    }
+    occup[np]=-1;
+  } 
+
+}
+
+/**********************************************/
+Bool_t  AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
+{
+
+  Int_t i;
+  for(i=0;i<nn;i++)
+    {
+      if (lis[i]==idx) return kFALSE;
+    }
+  return kTRUE;
+}
+
+/**********************************************/
+void AliITSpackageSSD::PrintClusters()
+{
+
+Int_t i,j;
+cout<<"SIDE P\n";
+for(i=0;i<fNclustersP;i++)
+ {
+   cout<<i<<".  IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<"     C. IDXs : ";
+   for(j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
+    {
+      cout<<GetPSideCluster(i)->GetCross(j)<<" ";
+    }
+ //  if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
+ //  else cout<<"BAD SIDE ==N\n";
+    cout<<"\n";
+   
+ }
+
+cout <<"SIDE N\n";
+for(i=0;i<fNclustersN;i++)
+ {
+   cout<<i<<".  IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<"     C. IDXs : ";
+   for(j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
+    {
+      cout<<GetNSideCluster(i)->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;i<fNclustersP;i++)
+ {
+   GetPSideCluster(i)->Consume();
+ }
+
+for(i=0;i<fNclustersN;i++)
+ {
+   GetNSideCluster(i)->Consume();
+ }
+
+}
+
+/**********************************************/
+
+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<fNclustersP-1;i++)
+  {
+    if(GetPSideClusterIdx(i) == OI)
+       return GetPSideClusterIdx(i+1);
+  }
+ return -1;
+}
+/**********************************************/
+Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
+{
+ //Returns index of previous P cluster  OI in package; OI == Original Inedx (in TClonesArray)
+ //if not egsist return -1;
+ Int_t i;
+ for(i =1; i<fNclustersP;i++)
+  {
+    if(GetPSideClusterIdx(i) == OI)
+       return GetPSideClusterIdx(i-1);
+  }
+  return -1;
+}
+/**********************************************/
+Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
+{
+//Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
+ //if not egsist return -1;
+ Int_t i;
+ for(i =0; i<fNclustersN-1;i++)
+  {
+    if(GetNSideClusterIdx(i) == OI)
+       return GetNSideClusterIdx(i+1);
+  }
+ return -1;
+
+}
+/**********************************************/
+Int_t  AliITSpackageSSD::GetPrvNIdx(Int_t OI)
+{
+ //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
+ //if not egsist return -1;
+ Int_t i;
+ for(i =1; i<fNclustersN;i++)
+  {
+    if(GetNSideClusterIdx(i) == OI)
+       return GetNSideClusterIdx(i-1);
+  }
+  return -1;
+}
+
+void  AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
+{
+  // split package of clusters
+  Int_t p=-1, n=-1;
+  Int_t i;
+  for(i=0;i<fNclustersN;i++)
+   {
+     if((*fClusterNIndexes)[i]==ni) 
+      {
+        n = i;
+       break;
+      }
+    } 
+   
+  for(i=0;i<fNclustersP;i++)
+   {
+     if((*fClusterPIndexes)[i]==pi) 
+      {
+        p = i;
+       break;
+      }
+    }  
+  if (debug) cout<<" p = "<<p<<"  n = "<<n;
+  if ((p==-1)||(n==-1)) return;
+  
+  for(i=p;i<fNclustersP;i++)
+   {
+     pkg->AddPSideCluster(GetPSideClusterIdx(i));       
+   }
+  fNclustersP = p;
+  
+  for(i=n;i<fNclustersN;i++)
+   {
+     pkg->AddNSideCluster(GetNSideClusterIdx(i));       
+   }
+  fNclustersN = n;
+  cout<<"  After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";
+}
diff --git a/ITS/AliITSpackageSSD.h b/ITS/AliITSpackageSSD.h
new file mode 100644 (file)
index 0000000..0bf70ac
--- /dev/null
@@ -0,0 +1,112 @@
+#ifndef ALIITSPACKAGESSD_H
+#define ALIITSPACKAGESSD_H
+//Class describing set of AliITSoneSideClusterSSDs, which contact each other.
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+//
+#include "TObject.h"
+#include "TArrayI.h"
+#include "TClonesArray.h"
+#include "AliITS.h"
+
+#include "AliITSclusterSSD.h"
+
+
+class AliITSpackageSSD : public TObject
+{
+ public:
+  AliITSpackageSSD(); 
+
+  AliITSpackageSSD(Int_t len, TClonesArray *clustersP, TClonesArray *clustersP);  
+  AliITSpackageSSD(TClonesArray *clustersP, TClonesArray *clustersP);  
+
+  ~AliITSpackageSSD();
+  
+  AliITSpackageSSD(const AliITSpackageSSD &package); 
+  AliITSpackageSSD&  operator=( const AliITSpackageSSD & package);
+  //Add cluster in side N, clindex is an index of this cluster in TClonesArray
+  
+  void     AddNSideCluster(Int_t clindex) {(*fClusterNIndexes)[fNclustersN++]=clindex;} 
+  void     AddPSideCluster(Int_t clindex) {(*fClusterPIndexes)[fNclustersP++]=clindex;} 
+
+  void     AddCluster(Int_t clindex, Bool_t side){
+             (side)?(*fClusterNIndexes)[fNclustersN++]= 
+                   clindex:(*fClusterPIndexes)[fNclustersP++]=clindex;}
+       
+//Returns index of one side cluster in TClonesArray, NOT AliITSclusterSSD
+  Int_t    GetNSideClusterIdx(Int_t index); //input index is number of cluster in this package 
+  Int_t    GetPSideClusterIdx(Int_t index); //returns index in TClonesArray
+  Int_t    GetClusterIdx(Int_t index,Bool_t side)
+               {return (side)?GetPSideClusterIdx(index):GetNSideClusterIdx(index);}
+  AliITSclusterSSD*    GetNSideCluster(Int_t index);
+  AliITSclusterSSD*    GetPSideCluster(Int_t index); //index is 
+  AliITSclusterSSD*    GetCluster(Int_t index, Bool_t side)
+               {return (side)?GetPSideCluster(index):GetNSideCluster(index);}
+                       
+  Int_t    GetNextPIdx(Int_t OI); //Returns index of next P cluster in package; OI == Original Inedx (in TClonesArray)
+  Int_t    GetPrvPIdx(Int_t OI);  //Returns index of previous P cluster in package; OI == Original Inedx (in TClonesArray)
+  Int_t    GetNextNIdx(Int_t OI); //Returns index of next N cluster in package; OI == Original Inedx (in TClonesArray)
+  Int_t    GetPrvNIdx(Int_t OI);  //Returns index of previous N cluster in package; OI == Original Inedx (in TClonesArray)
+
+  Int_t    GetNumOfClustersN (){return fNclustersN;}  
+  Int_t    GetNumOfClustersP(){return fNclustersP;}   
+  Int_t    GetNumOfClusters() {return fNclustersP+fNclustersN;}  
+  Int_t    GetNumOfClusters(Bool_t side) {return (side)?fNclustersP:fNclustersN;}
+  
+  //returns number of clusters belonging to package,
+  //that crosses with only one cluster on the other side 
+  //There might be only 2 such a clusters:
+  //on the begining and on the end of the package
+  //
+  Bool_t    GetClusterWithOneCross(Int_t & index, Bool_t& side );  
+  void      DelCluster(Int_t index, Bool_t side);
+  void      DelPCluster(Int_t index);
+  void      DelNCluster(Int_t index);
+  void      DelClusterOI(Int_t index, Bool_t side); //OI indicates that it is Original Index
+  void      DelPClusterOI(Int_t index); //it means value in look up table
+  void      DelNClusterOI(Int_t index);  
+  
+  void      SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg);
+  void      GetAllCombinations(Int_t**array,Int_t &num,Int_t size);
+  
+  void      ConsumeClusters();
+  void      PrintClusters();
+  
+protected:
+  
+  TClonesArray *fClustersN;   //Pointer to array of clusters - only to have direct acces to 
+  TClonesArray *fClustersP;   //clusters
+  Int_t    fNclustersN;
+  Int_t    fNclustersP;
+  TArrayI *fClusterNIndexes;
+  TArrayI *fClusterPIndexes;
+  static const Bool_t SIDEP=kTRUE;
+  static const Bool_t SIDEN=kFALSE;
+
+
+/***************/
+/*   Methods   */
+/***************/
+
+  
+  void    MakeCombin(Int_t**arr, Int_t& nu, Int_t np, Int_t *occup,Int_t size);
+  Bool_t  IsFree(Int_t idx, Int_t nn, Int_t *lis);
+  
+
+                
+private:
+                
+//-------------------------------------------------------               
+  ClassDef(AliITSpackageSSD,1) 
+};
+
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSresponse.h b/ITS/AliITSresponse.h
new file mode 100644 (file)
index 0000000..ba88627
--- /dev/null
@@ -0,0 +1,110 @@
+#ifndef ALIITSRESPONSE_H
+#define ALIITSRESPONSE_H
+
+
+#include <TObject.h>
+#include <TF1.h>
+#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 (file)
index 0000000..6662c84
--- /dev/null
@@ -0,0 +1,158 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                         *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <TMath.h>
+
+#include "AliITSgeom.h"
+#include "AliITSresponseSDD.h"
+#include "AliITS.h"
+#include "AliRun.h"
+
+class AliITS;
+
+//___________________________________________
+ClassImp(AliITSresponseSDD)    
+
+AliITSresponseSDD::AliITSresponseSDD()
+{
+  // constructor
+   SetMaxAdc();
+   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->fMaxAdc = source.fMaxAdc;
+  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->fMaxAdc = source.fMaxAdc;
+  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.ReadStaticArray(fCPar);
+      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 (file)
index 0000000..a06de3c
--- /dev/null
@@ -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
+    fMaxAdc=p1;
+  }
+  virtual Float_t MaxAdc()  {
+    // Get maximum Adc-count value
+    return fMaxAdc;
+  }                       
+  
+  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*&param) {
+    // 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 (file)
index 0000000..0db68b7
--- /dev/null
@@ -0,0 +1,32 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <TMath.h>
+
+#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 (file)
index 0000000..221a706
--- /dev/null
@@ -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 (file)
index 0000000..17828d4
--- /dev/null
@@ -0,0 +1,141 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                         *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <TMath.h>
+
+#include "AliITSresponseSSD.h"
+#include "AliITSgeom.h"
+
+ClassImp(AliITSresponseSSD)    
+//----------------------------------------------------------
+AliITSresponseSSD::AliITSresponseSSD()
+{
+  // constructor
+  SetDiffCoeff();
+  SetNoiseParam();
+  SetDataType();
+  SetSigmaSpread();
+  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; i++) {
+    fDetPar[i]=par[i];
+    //printf("\n CompressPar %d %d \n",i,fCPar[i]);
+    
+  } 
+}
+void AliITSresponseSSD::GetDetParam(Float_t  *par)
+{
+  // get det param
+  Int_t i;  
+  for(i=0; i<fNPar; i++) {
+    par[i]=fDetPar[i];
+  }
+}
+
+//______________________________________________________________________________
+void AliITSresponseSSD::Streamer(TBuffer &R__b)
+{
+   // Stream an object of class AliITSresponseSSD.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      AliITSresponse::Streamer(R__b);
+      R__b >> 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 (file)
index 0000000..9d3c6ff
--- /dev/null
@@ -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 (file)
index 0000000..071c5c5
--- /dev/null
@@ -0,0 +1,117 @@
+#ifndef ALIITSSEGMENTATION_H
+#define ALIITSSEGMENTATION_H
+
+
+#include <TObject.h>
+#include <TF1.h>
+
+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 (file)
index 0000000..4889373
--- /dev/null
@@ -0,0 +1,153 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <TMath.h>
+
+#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 (file)
index 0000000..8ec4408
--- /dev/null
@@ -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 (file)
index 0000000..69b0d43
--- /dev/null
@@ -0,0 +1,320 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <TMath.h>
+
+#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<fNpx;i++) fCellSizeX[i] = 50.0; // microns all the same
+    for(i=0;i<fNpz;i++) fCellSizeZ[i] = ZpitchFromCol300(i); // microns
+    for(i=fNpz;i<280;i++) fCellSizeZ[i] = 0.0; // zero out rest of array
+    fDx = 0;
+    for(i=0;i<fNpx;i++) fDx += fCellSizeX[i];
+    fDz = 0;
+    for(i=0;i<fNpz;i++) fDz += fCellSizeZ[i];
+    fDy = 300.0; //microns  SPD sensitive layer thickness
+}
+
+//------------------------------
+void AliITSsegmentationSPD::Init(){
+// Initialize infromation for 6 read out chip 425X50 micron pixel SPD 
+// detectors. This chip is 150 microns thick by 1.28 cm in x by 8.375 cm
+// long. It has 256  50 micron pixels in x and 197 mostly 425 micron size
+// pixels in z. The two pixels between each readout chip are 625 microns long.
+
+    Int_t i;
+    //const Float_t kconv=10000.;
+    fNpx = 256; // The number of X pixel Cell same as in fCellSizeX array size
+    fNpz = 192; // The number of Z pixel Cell same as in fCellSizeZ array size
+    for(i=0;i<fNpx;i++) fCellSizeX[i] = 50.0; // microns all the same
+    for(i=0;i<fNpz;i++) fCellSizeZ[i] = ZpitchFromCol(i); // microns
+    for(i=fNpz;i<280;i++) fCellSizeZ[i] = 0.0; // zero out rest of array
+    fDx = 0;
+    for(i=0;i<fNpx;i++) fDx += fCellSizeX[i];
+    fDz = 0;
+    for(i=0;i<fNpz;i++) fDz += fCellSizeZ[i];
+    fDy = 300.0; //microns  SPD sensitive layer thickness
+    printf(" AliITSsegmentationSPD - Init: fNpx fNpz fDx fDz %d %d %f %f\n",fNpx, fNpz, fDx, fDz);
+
+}
+//------------------------------
+void AliITSsegmentationSPD::SetNCells(Int_t p1, Int_t p2){
+  // for SPD this function should be used ONLY when a beam test setup 
+  // configuration is studied
+
+    fNpx=p1;
+    fNpz=p2;
+
+}
+//------------------------------
+void AliITSsegmentationSPD::SetDetSize(Float_t p1, Float_t p2, Float_t p3){
+  // for SPD this function should be used ONLY when a beam test setup 
+  // configuration is studied
+
+    fDx=p1;
+    fDz=p2;
+    fDy=p3;
+
+}
+//------------------------------
+Float_t AliITSsegmentationSPD::Dpx(Int_t i){
+   //returs x pixel pitch for a give pixel
+   return fCellSizeX[i];
+}
+//------------------------------
+Float_t AliITSsegmentationSPD::Dpz(Int_t i){
+  // returns z pixel pitch for a give pixel
+   return ZpitchFromCol(i);
+}
+//------------------------------
+void AliITSsegmentationSPD::GetCellIxz(Float_t &x,Float_t &z,Int_t &ix,Int_t &iz){
+//  Returns pixel coordinates (ix,iz) for given real local coordinates (x,z)
+//
+
+    // expects x, z in microns
+
+    // same segmentation on x
+    Float_t dpx=Dpx(0);
+    ix = (Int_t)(x/dpx + 1);
+    // different segmentation on z
+    iz = (Int_t)(ColFromZ(z) + 1);
+
+    x /= dpx;
+    z = ColFromZ(z);
+
+    if (iz >  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 (file)
index 0000000..6c8a618
--- /dev/null
@@ -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 (file)
index 0000000..63080eb
--- /dev/null
@@ -0,0 +1,132 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <TMath.h>
+
+#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 (file)
index 0000000..a85224d
--- /dev/null
@@ -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 (file)
index 0000000..04c4024
--- /dev/null
@@ -0,0 +1,44 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#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 (file)
index 0000000..d773515
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef ALIITSSIMULATION_H
+#define ALIITSSIMULATION_H
+
+#include <TObject.h>
+
+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 (file)
index 0000000..9a51c3e
--- /dev/null
@@ -0,0 +1,184 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                          *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log$
+Revision 1.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 <TParticle.h>
+#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;h<nhit;h++){
+    hit = mod->GetHit(h);
+    hit->GetPositionL(x,y,z,t);
+    if(ifirst) {x1=x;y1=y;z1=z;}
+    e += hit->GetIonization();
+    trk = hit->GetTrack();
+    fSx->AddValue((Double_t)x,weight);
+    fSz->AddValue((Double_t)z,weight);
+    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
+       AddSPD(e,mod,trk);
+       break;
+      case 3: case 4:  // SDDs
+       AddSDD(e,mod,trk);
+       break;
+      case 5: case 6:  // SSDs
+       AddSSD(e,mod,trk);
+       break;
+      } // end switch
+      fSx->Reset();
+      fSz->Reset();
+      e = 0.;
+      ifirst = 1;
+      continue;
+    }// end if
+  } // end for h
+}
+//_______________________________________________________________________
+void AliITSsimulationFastPoints::AddSPD(Float_t &e,
+                                        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);
+
+  (mod->GetITS())->AddRecPoint(rpSPD);
+}
+//_______________________________________________________________________
+void AliITSsimulationFastPoints::AddSDD(Float_t &e,
+                                        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);
+
+  (mod->GetITS())->AddRecPoint(rpSDD);
+}
+//_______________________________________________________________________
+void AliITSsimulationFastPoints::AddSSD(Float_t &e,
+                                        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);
+
+  (mod->GetITS())->AddRecPoint(rpSSD);
+}
+//_______________________________________________________________________
diff --git a/ITS/AliITSsimulationFastPoints.h b/ITS/AliITSsimulationFastPoints.h
new file mode 100644 (file)
index 0000000..6e2e52f
--- /dev/null
@@ -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 (file)
index 0000000..363aa3f
--- /dev/null
@@ -0,0 +1,1390 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+#include <iostream.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+
+
+#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
+/*
+<img src="picts/ITS/AliITShit_Class_Diagram.gif">
+</pre>
+<br clear=left>
+<font size=+2 color=red>
+<p>This show the relasionships between the ITS hit class and the rest of Aliroot.
+</font>
+<pre>
+*/
+//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; i<e; i++) power *= b;
+  return power;
+}
+
+//_____________________________________________
+
+void FastFourierTransform(AliITSetfSDD *alisddetf,Double_t *real,
+                          Double_t *imag,Int_t direction) {
+  // Do a Fast Fourier Transform
+
+  Int_t samples = alisddetf->GetSamples();
+  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; j<samples; j += m1) {
+      Int_t p = 0;
+      for(k=j; k<= j+m-1; k++) {
+       Double_t wsr = alisddetf->GetWeightReal(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<samples; j++) {
+    Int_t j1 = j;
+    Int_t p = 0;
+    Int_t i1;
+    for(i1=1; i1<=l; i1++) {
+      Int_t j2 = j1;
+      j1 /= 2;
+      p = p + p + j2 - j1 - j1;
+    }
+    if(p >= 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; i<samples; i++) {
+      *(real+i) /= samples;
+      *(imag+i) /= samples;
+    }
+  }
+  return;
+}
+//_____________________________________________________________________________
+
+AliITSsimulationSDD::AliITSsimulationSDD(){
+  // Default constructor
+
+  fResponse = 0;
+  fSegmentation = 0;
+  fHis = 0;
+  fD.Set(0);
+  fT1.Set(0);
+  fT2.Set(0);
+  fTol.Set(0);
+}
+//_____________________________________________________________________________
+AliITSsimulationSDD::AliITSsimulationSDD(AliITSsimulationSDD &source){
+  // Copy constructor to satify Coding roules only.
+  if(this==&source) return;
+  printf("Not allowed to make a copy of AliITSsimulationSDD "
+         "Using default creater instead\n");
+  AliITSsimulationSDD();
+}
+//_____________________________________________________________________________
+AliITSsimulationSDD& AliITSsimulationSDD::operator=(AliITSsimulationSDD 
+                                                     &source){
+  // Copy constructor to satify Coding roules only.
+  if(this==&source) return *this;
+  printf("Not allowed to make a = with AliITSsimulationSDD "
+         "Using default creater instead\n");
+  return *this ;
+}
+//_____________________________________________________________________________
+
+AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
+                                         AliITSresponse *resp) {
+  // Constructor
+      fResponse = resp;
+      fSegmentation = seg;
+
+      fHitMap2 = new AliITSMapA2(fSegmentation);
+      fHitMap1 = new AliITSMapA1(fSegmentation);
+
+      //
+      fNofMaps=fSegmentation->Npz();
+      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
+        // ReadBaseline();
+
+        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;
+    if(!padr) padr=new TClonesArray("TVector",1000);
+    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; ii<nhits; ii++) {
+       AliITShit *hit = (AliITShit*) fHits->At(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;
+             ListOfFiredCells(arg,timeAmplitude,list,padr);
+       } // 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; 
+                      
+  padr->Delete(); 
+
+  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 countadr=arg[4];
+                   
+                    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)) {
+                     
+                       new((*padr)[countadr++]) TVector(2);
+                       TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
+                       trinfo(0)=(Float_t)idtrack;
+                       trinfo(1)=(Float_t)timeAmplitude;
+
+                       list->AddAtAndExpand(
+                           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();
+                       trlist->Add(&trinfo);
+
+                   } 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;
+                           trlist->AddAt(&trinfo,lastentry);
+                       } else {
+                         
+                           new((*padr)[countadr++]) TVector(2);
+                           TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
+                           trinfo(0)=(Float_t)idtrack;
+                           trinfo(1)=(Float_t)timeAmplitude;
+                         
+                           trlist->Add(&trinfo);
+                       }
+
+#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;tr<nptracks;tr++) {
+                               TVector *pptrkp=(TVector*)trlist->At(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;
+                    arg[4]=countadr;
+
+
+}
+
+
+//____________________________________________
+
+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;
+       }
+        fITS->AddDigit(1,phys,digits,tracks,charges); 
+    } 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 "<<nptracks<<endl;
+        nptracks=20;
+      }
+      Int_t tr;
+      for(tr=0;tr<nptracks;tr++) {
+         TVector &pp  =*((TVector*)trlist->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 ) {
+        for(i=0; i<nptracks; i++) {
+            tracks[i]=trk[i];
+            charges[i]=chtrk[i];
+        }
+        for(i=nptracks; i<3; i++) {
+            tracks[i]=0;
+            charges[i]=0;
+        }
+      } else {
+        for(i=0; i<3; i++) {
+            tracks[i]=trk[i];
+            charges[i]=chtrk[i];
+        }
+      }
+
+      fITS->AddDigit(1,phys,digits,tracks,charges); 
+    }
+
+}
+
+//____________________________________________
+
+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<imax;i++){
+    qmax=0;
+    jmax=0;
+    
+    for(j=0;j<ntr;j++){
+      
+      if((i == 1 && j == idx[i-1] )
+        ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
+      
+      if(charges[j] > 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 maxadc = fResponse->MaxAdc();    
+  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
+      if (readfile) ReadBaseline();
+      readfile=kFALSE;
+  } 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);
+    for(k=0;k<fMaxNofSamples;k++) {
+        if (!first) {
+          // analog to digital ?
+          Double_t signal = OutZR[k]*norm;
+           if (signal > maxadc) signal = maxadc;
+          // 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; k<fMaxNofSamples; k++) {
+            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;
+            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]);
+       */
+   }
+}
+
+//____________________________________________
+void AliITSsimulationSDD::ReadBaseline(){
+      // 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("<Convert8to10> 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; i<fNofMaps; i++) {
+        CompressionParam(i,db,tl,th);
+        nz=0; 
+        nl=0;
+        nh=0;
+        low=0;
+       for(j=0; j<fMaxNofSamples; j++) {
+           Int_t signal=(Int_t)(fHitMap2->GetSignal(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; in<nn; in++) {
+       ix=Xlist[in];
+        iy=Ylist[in];
+        if (fHitMap2->TestHit(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);
+                AddDigit(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; i<fNofMaps/2; i++) {
+            Bool_t firstSignal=kTRUE;
+            CompressionParam(k*i,decr,thres); 
+            for(j=0; j<fMaxNofSamples; j++) {
+                Int_t signal=(Int_t)(fHitMap2->GetSignal(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;
+                    AddDigit(k*i,j,last+diff);
+                } else {
+                   AddDigit(k*i,j,signal);
+                }
+                 
+                 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 "<<fFileName<<endl;
+           OutFile=new TFile(fFileName,"recreate");
+           cout<<"I have opened "<<fFileName<<" file "<<endl;
+       }           
+       open=kFALSE;
+       OutFile->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; i<fNofMaps; i++) {
+        for(j=0; j<fMaxNofSamples; j++) {
+             Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j));
+            signal = Convert10to8(signal);
+            signal = Convert8to10(signal); // ?
+             digits[0]=i;
+             digits[1]=j;
+             digits[2]=signal;
+             fITS->AddRealDigit(1,digits);
+       }
+    }
+} 
+//____________________________________________
+
+void AliITSsimulationSDD::CreateHistograms(){
+  // Creates histograms of maps for debugging
+
+      Int_t i;
+      for(i=0;i<fNofMaps;i++) {
+          TString *sddName = new TString("sdd_");
+          Char_t candNum[4];
+          sprintf(candNum,"%d",i+1);
+          sddName->Append(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;i<fNofMaps;i++ ) {
+       if ((*fHis)[i])    ((TH1F*)(*fHis)[i])->Reset();
+    }
+
+}
+
+
+//____________________________________________
+
+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; i<fNofMaps; i++)  (*fHis)[i]->Write(); //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;i<fNofMaps;i++) {
+    Int_t nOfBinsA = ((TH1F*)(*fHis)[i])->GetNbinsX();
+    for(k=0;k<nOfBinsA;k++) {
+      Float_t content = ((TH1F*)(*fHis)[i])->GetBinContent(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 (file)
index 0000000..1b0b346
--- /dev/null
@@ -0,0 +1,117 @@
+#ifndef ALIITSSIMULATIONSDD_H
+#define ALIITSSIMULATIONSDD_H
+
+
+#include <TH1.h>
+#include <TFile.h>
+#include <TNtuple.h>
+#include <TRandom.h> 
+#include <TVector.h>
+#include <TArrayI.h>
+
+
+#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,
+                        TClonesArray *padr);
+  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 (file)
index 0000000..af2d4af
--- /dev/null
@@ -0,0 +1,541 @@
+#include <iostream.h>
+#include <TRandom.h>
+#include <TH1.h>
+
+#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 sigmaDif;
+    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;hit<nhits;hit++) {
+        AliITShit *iHit = (AliITShit*) fHits->At(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];iz<indexRange[1]+1;iz++){
+    for(ix=indexRange[2];ix<indexRange[3]+1;ix++){
+      
+      signal=fMapA2->GetSignal(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(signal<lowest) continue; // neglect this track
+
+          if (signal>highest){
+            *(pList[globalIndex]+5) = middle;
+            *(pList[globalIndex]+4) = highest;
+            *(pList[globalIndex]+3) = signal;
+
+            *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
+            *(pList[globalIndex]+1) = *pList[globalIndex];
+            *pList[globalIndex] = label;
+         }
+          else if (signal>middle){
+            *(pList[globalIndex]+5) = middle;
+            *(pList[globalIndex]+4) = signal;
+
+            *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
+            *(pList[globalIndex]+1) = label;
+         }
+          else{
+            *(pList[globalIndex]+5) = signal;
+            *(pList[globalIndex]+2) = label;
+         }
+        }
+    } // end 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;iz<fNPixelsZ;iz++){
+    for(ix=0;ix<fNPixelsX;ix++){
+      electronics = fBaseline + fNoise*random->Gaus();
+      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;
+        aliITS->AddDigit(0,phys,digits,tracks,charges);
+         if(pList[gi]) delete [] pList[gi];
+      }
+    }
+  }
+  delete [] pList;
+
+
+}
+
+
+//____________________________________________
+
+void AliITSsimulationSPD::CreateHistograms() {
+  // CreateHistograms
+
+      Int_t i;
+      for(i=0;i<fNPixelsZ;i++) {
+          TString *spdname = new TString("spd_");
+          Char_t candnum[4];
+          sprintf(candnum,"%d",i+1);
+          spdname->Append(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;i<fNPixelsZ;i++ ) {
+       if ((*fHis)[i])    ((TH1F*)(*fHis)[i])->Reset();
+    }
+
+}
diff --git a/ITS/AliITSsimulationSPD.h b/ITS/AliITSsimulationSPD.h
new file mode 100644 (file)
index 0000000..095052b
--- /dev/null
@@ -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 (file)
index 0000000..81a2958
--- /dev/null
@@ -0,0 +1,435 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include <stdio.h>
+#include <TObjArray.h>
+
+#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; i<fNstrips; i++) {
+       (*fP)[i] = 0;
+       (*fN)[i] = 0;
+       fTracksP[i].ZeroTracks();
+       fTracksN[i].ZeroTracks();
+    }
+    
+    for(i=0; i<nhits; i++) {
+       Int_t idtrack=mod->GetHitTrackIndex(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 (++hitNo<nhits) {
+           ionization = hitE->GetIonization(); 
+           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; i<fSteps; i++) {
+        
+      //        arrayEP[i] = gRandom->Landau(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
+       
+    for(i=0; i<fSteps; i++) {
+    
+        arrayEP[i] = kconv * arrayEP[i] * (ionization / eP); 
+        arrayEN[i] = kconv * arrayEN[i] * (ionization / eN);        
+    }    
+        
+    dx /= fSteps;
+    dz /= fSteps;  
+
+    Float_t sigmaP, sigmaN; 
+    fResponse->SigmaSpread(sigmaP,sigmaN); 
+
+    //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; i<fSteps; i++) {
+        
+        Int_t j;
+       
+        fSegmentation->GetCellIxz(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);   
+               (*dict).AddTrack(track);
+            } 
+       }  // 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
+               (*dict).AddTrack(track);
+            } 
+        }  // 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; i<fNstrips; i++) {
+       (*fP)[i] += gRandom->Gaus(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; i<fNstrips-1; i++) {
+      (*fP)[i] += (*fP)[i-1]*fDCS->GetCouplingPL() + (*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<fNstrips; i++) {
+       (*fP)[i] = ((*fP)[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; i<fNstrips; i++) {
+       if (!(fDCS->IsValidP(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; i<fNstrips; i++) { 
+       if ((*fP)[i] < noiseP*4) continue;
+          digits[0]=1;
+          digits[1]=i;
+          digits[2]=(int)(*fP)[i];
+          for(j=0; j<(fTracksP+i)->GetNTracks(); j++) {
+             if(j>2) continue;
+             tracks[j] = (fTracksP+i)->GetTrack(j);
+             charges[j] = 0;
+          }
+          its->AddDigit(2,phys,digits,tracks,charges);
+          
+          //cout << (fTracksP+i)->GetNTracks(); 
+          //
+         //if ((fTracksP+i)->GetNTracks() == 0) {
+          //   cout << d.fCoord2 << " " << d.fSignal << "\n"; 
+          //}
+    }
+    
+    
+    for(i=0; i<fNstrips; i++) {
+       if ((*fN)[i] < noiseN*4) continue;
+          digits[0]=0;
+          digits[1]=i;
+          digits[2]=(int)(*fN)[i];
+          for(j=0; j<(fTracksN+i)->GetNTracks(); j++) {
+             if(j>2) continue;
+             tracks[j] = (fTracksN+i)->GetTrack(j); 
+             charges[j] = 0;
+          }
+          its->AddDigit(2,phys,digits,tracks,charges);
+          
+          //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 (file)
index 0000000..359d0ca
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef ALIITSSIMULATIONSSD_H
+#define ALIITSSIMULATIONSSD_H
+
+#include <TArrayF.h>
+
+#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 (file)
index 0000000..e029abb
--- /dev/null
@@ -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 <stdio.h>
+#include <math.h>
+#include <TMath.h>
+
+#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;i<order;i++) {fx[i] = 0.0; fw[i] = 0.0;}
+    fN = 0;
+    return;
+}
+
+AliITSstatistics::~AliITSstatistics(){
+//
+// default destructor
+//
+    if(fx!=0) delete[] fx;
+    if(fw!=0) delete[] fw;
+    fx = 0;
+    fw = 0;
+    fN = 0;
+    fOrder = 0;
+}
+//_______________________________________________________________
+AliITSstatistics& AliITSstatistics::operator=(AliITSstatistics &source){
+// operator =
+
+     Int_t i;
+     if(this==&source) return *this;
+     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;i<source.fOrder;i++){
+        this->fx[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;i<source.fOrder;i++){
+      this->fx[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<fOrder;i++) {fx[i] = 0.0; fw[i] = 0.0;}
+    fN = 0;
+    return;
+}
+
+void AliITSstatistics::AddValue(Double_t x,Double_t w=1.0){
+//
+// accumulate element x with weight w.
+//
+    Double_t y=1.0,z=1.0;
+    Int_t i;
+
+
+    if(isinf(y)!=0||isinf(x)!=0||isinf(w)!=0) return;
+    if(isnan(y)!=0||isnan(x)!=0||isnan(w)!=0) return;
+    fN++;
+    for(i=0;i<fOrder;i++){
+       y *= x;
+       z *= w;
+       fx[i] += y*w;
+       fw[i] += z;
+    } // end for i
+}
+
+Double_t AliITSstatistics::GetNth(Int_t order){
+// This give the unbiased estimator for the RMS.
+    Double_t s;
+
+    if(fw[0]!=0.0&&order<=fOrder) s = fx[order-1]/fw[0];
+    else {
+       s = 0.0;
+       printf("AliITSstatistics: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
+              fOrder,fN,fw[0]);
+    } // end else
+    return s;
+}
+
+Double_t AliITSstatistics::GetRMS(){
+// This give the unbiased estimator for the RMS.
+    Double_t x,x2,w,ww,s;
+
+    x  = GetMean(); // first order
+    x2 = GetNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+    return TMath::Sqrt(s);
+}
+
+Double_t AliITSstatistics::GetErrorMean(){
+//This is the error in the mean or the square root of the variance of the mean.
+    Double_t rms,w,ww,s;
+
+    rms = GetRMS();
+    w   = fw[0];
+    ww  = fw[1];
+    s   = rms*rms*ww/(w*w);
+    return TMath::Sqrt(s);
+}
+
+
+Double_t AliITSstatistics::GetErrorRMS(){
+//This is the error in the mean or the square root of the variance of the mean.
+// at this moment this routine is only defined for weights=1.
+    Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
+
+    if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
+    x  = GetMean(); // first order
+    x2 = GetNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+
+    m2  = s;
+    n   = (Double_t) GetN();
+    x3  = GetNth(3);
+    x4  = GetNth(4);
+// This equation assumes that all of the weights are equal to 1.
+    m4  = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
+    s   = (m4-(n-3.)*m2*m2/(n-1.))/n;
+    return TMath::Sqrt(s);
+}
+//_______________________________________________________________________
+void AliITSstatistics::Streamer(TBuffer &R__b){
+   // Stream an object of class AliITSstatistics.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      TObject::Streamer(R__b);
+      R__b >> fN;
+      R__b >> fOrder;
+      R__b.ReadArray(fx);
+      R__b.ReadArray(fw);
+   } 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 (file)
index 0000000..0c2bd10
--- /dev/null
@@ -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,Float_t w){AddValue((Double_t)x,(Double_t)w);} //float
+  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 (file)
index 0000000..4dbb867
--- /dev/null
@@ -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 <stdio.h>
+#include <math.h>
+#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;i<order;i++) {fx[i] = 0.0;fy[i] = 0.0;
+                          fyx[i] = 0.0; fw[i] = 0.0;}
+    fN = 0;
+    return;
+}
+
+AliITSstatistics2::~AliITSstatistics2(){
+//
+// destructor
+//
+    if(fx!=0)  delete[] fx;
+    if(fy!=0)  delete[] fy;
+    if(fyx!=0) delete[] fyx;
+    if(fw!=0)  delete[] fw;
+    fx  = 0;
+    fy  = 0;
+    fyx = 0;
+    fw  = 0;
+    fN  = 0;
+    fOrder = 0;
+}
+
+//_______________________________________________________________
+AliITSstatistics2& AliITSstatistics2::operator=(AliITSstatistics2 &source){
+// operator =
+
+  Int_t i;
+  if(this==&source) return *this;
+  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;i<source.fOrder;i++){
+      this->fx[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;i<source.fOrder;i++){
+      this->fx[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<fOrder;i++) {fx[i] = 0.0;fy[i] = 0.0;
+                           fyx[i] = 0.0; fw[i] = 0.0;}
+    fN = 0;
+    return;
+}
+
+void AliITSstatistics2::AddValue(Double_t y,Double_t x,Double_t w=1.0){
+//
+// add next x,y pair to statistics
+//
+    Double_t xs=1.0,ys=1.0,yxs=1.0,ws=1.0;
+    Int_t i;
+
+    if(isinf(y)!=0||isinf(x)!=0||isinf(w)!=0) return;
+    if(isnan(y)!=0||isnan(x)!=0||isnan(w)!=0) return;
+    fN++;
+    for(i=0;i<fOrder;i++){
+       xs  *= x;
+       ys  *= y;
+       yxs *= x*y;
+       ws  *= w;
+       fx[i]  += xs*w;
+       fy[i]  += ys*w;
+       fyx[i] += yxs*w;
+       fw[i]  += ws;
+    } // end for i
+}
+
+Double_t AliITSstatistics2::GetXNth(Int_t order){
+//
+// This give the unbiased estimator for the RMS.
+//
+
+    Double_t s;
+
+    if(fw[0]!=0.0&&order<=fOrder) s = fx[order-1]/fw[0];
+    else {
+       s = 0.0;
+       printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
+              fOrder,fN,fw[0]);
+    } // end else
+    return s;
+}
+Double_t AliITSstatistics2::GetYNth(Int_t order){
+//
+// This give the unbiased estimator for the RMS.
+//
+    Double_t s;
+
+    if(fw[0]!=0.0&&order<=fOrder) s = fy[order-1]/fw[0];
+    else {
+       s = 0.0;
+       printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
+              fOrder,fN,fw[0]);
+    } // end else
+    return s;
+}
+Double_t AliITSstatistics2::GetYXNth(Int_t order){
+// This give the unbiased estimator for the RMS.
+    Double_t s;
+
+    if(fw[0]!=0.0&&order<=fOrder) s = fyx[order-1]/fw[0];
+    else {
+       s = 0.0;
+       printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
+              fOrder,fN,fw[0]);
+    } // end else
+    return s;
+}
+Double_t AliITSstatistics2::GetRMSX(){
+// This give the unbiased estimator for the RMS.
+    Double_t x,x2,w,ww,s;
+
+    x  = GetMeanX(); // first order
+    x2 = GetXNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+    return TMath::Sqrt(s);
+}
+Double_t AliITSstatistics2::GetRMSY(){
+// This give the unbiased estimator for the RMS.
+    Double_t x,x2,w,ww,s;
+
+    x  = GetMeanY(); // first order
+    x2 = GetYNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+    return TMath::Sqrt(s);
+}
+Double_t AliITSstatistics2::GetRMSYX(){
+// This give the unbiased estimator for the RMS.
+    Double_t x,x2,w,ww,s;
+
+    x  = GetMeanYX(); // first order
+    x2 = GetYXNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+    return TMath::Sqrt(s);
+}
+Double_t AliITSstatistics2::GetErrorMeanY(){
+//This is the error in the mean or the square root of the variance of the mean.
+    Double_t rms,w,ww,s;
+
+    rms = GetRMSY();
+    w   = fw[0];
+    ww  = fw[1];
+    s   = rms*rms*ww/(w*w);
+    return TMath::Sqrt(s);
+}
+Double_t AliITSstatistics2::GetErrorMeanX(){
+//This is the error in the mean or the square root of the variance of the mean.
+    Double_t rms,w,ww,s;
+
+    rms = GetRMSX();
+    w   = fw[0];
+    ww  = fw[1];
+    s   = rms*rms*ww/(w*w);
+    return TMath::Sqrt(s);
+}
+Double_t AliITSstatistics2::GetErrorMeanYX(){
+//This is the error in the mean or the square root of the variance of the mean.
+    Double_t rms,w,ww,s;
+
+    rms = GetRMSYX();
+    w   = fw[0];
+    ww  = fw[1];
+    s   = rms*rms*ww/(w*w);
+    return TMath::Sqrt(s);
+}
+
+
+Double_t AliITSstatistics2::GetErrorRMSY(){
+//This is the error in the mean or the square root of the variance of the mean.
+// at this moment this routine is only defined for weights=1.
+    Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
+
+    if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
+    x  = GetMeanY(); // first order
+    x2 = GetYNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+
+    m2  = s;
+    n   = (Double_t) GetN();
+    x3  = GetYNth(3);
+    x4  = GetYNth(4);
+// This equation assumes that all of the weights are equal to 1.
+    m4  = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
+    s   = (m4-(n-3.)*m2*m2/(n-1.))/n;
+    return TMath::Sqrt(s);
+}
+Double_t AliITSstatistics2::GetErrorRMSX(){
+//This is the error in the mean or the square root of the variance of the mean.
+// at this moment this routine is only defined for weights=1.
+    Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
+
+    if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
+    x  = GetMeanX(); // first order
+    x2 = GetXNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+
+    m2  = s;
+    n   = (Double_t) GetN();
+    x3  = GetXNth(3);
+    x4  = GetXNth(4);
+// This equation assumes that all of the weights are equal to 1.
+    m4  = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
+    s   = (m4-(n-3.)*m2*m2/(n-1.))/n;
+    return TMath::Sqrt(s);
+}
+Double_t AliITSstatistics2::GetErrorRMSYX(){
+//This is the error in the mean or the square root of the variance of the mean.
+// at this moment this routine is only defined for weights=1.
+    Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
+
+    if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
+    x  = GetMeanYX(); // first order
+    x2 = GetYXNth(2); // second order
+    w  = fw[0];     // first order - 1.
+    ww = fw[1];     // second order - 1.
+    if(w*w==ww) return (-1.0);
+    s = (x2-x*x)*w*w/(w*w-ww);
+
+    m2  = s;
+    n   = (Double_t) GetN();
+    x3  = GetYXNth(3);
+    x4  = GetYXNth(4);
+// This equation assumes that all of the weights are equal to 1.
+    m4  = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
+    s   = (m4-(n-3.)*m2*m2/(n-1.))/n;
+    return TMath::Sqrt(s);
+}
+//_______________________________________________________________________
+Double_t AliITSstatistics2::FitToLine(Double_t &a,Double_t &b){
+// fit to y = a+bx returns Chi squared or -1.0 if an error
+    Double_t c,d,e,f,g,h;
+
+    a = b = 0.0;
+    if(fOrder<2 || fN<3) return -1.0;
+    c = GetWN(1);
+    d = GetYN(1);
+    e = GetXN(1);
+    f = GetYXN(1);
+    g = GetXN(2);
+    h = c*g-e*e;
+    a = d*g-f*e;
+    b = c*f-d*e;
+    if(h!=0.0){
+       a = a/h;
+       b = b/h;
+    }else{
+       printf("AliITSstatistics2: Error in FitToLine vertical line\n");
+       return -1.0;
+    } // end if h
+    h = GetYN(2)+a*a*c+b*b*g-2.0*a*d-2.0*b*f+2.0*a*b*e;
+    h /= (Double_t)fN - 2.0;
+    return h;
+}
+//_______________________________________________________________________
+void AliITSstatistics2::Streamer(TBuffer &R__b){
+   // Stream an object of class AliITSstatistics2.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      TObject::Streamer(R__b);
+      R__b >> fN;
+      R__b >> fOrder;
+      R__b.ReadArray(fy);
+      R__b.ReadArray(fx);
+      R__b.ReadArray(fyx);
+      R__b.ReadArray(fw);
+   } 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 (file)
index 0000000..5004fcf
--- /dev/null
@@ -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