From e81897071a6c895e2796d84a2531f1385a0a1017 Mon Sep 17 00:00:00 2001 From: fca Date: Mon, 10 Jul 2000 16:07:20 +0000 Subject: [PATCH] Release version of ITS code --- ITS/AliITS.cxx | 344 +++-- ITS/AliITS.h | 58 +- ITS/AliITSAlignmentModule.cxx | 454 +++++++ ITS/AliITSAlignmentModule.h | 79 ++ ITS/AliITSAlignmentTrack.cxx | 400 ++++++ ITS/AliITSAlignmentTrack.h | 158 +++ ITS/AliITSClusterFinder.cxx | 11 +- ITS/AliITSClusterFinder.h | 18 +- ITS/AliITSClusterFinderSDD.cxx | 105 +- ITS/AliITSClusterFinderSDD.h | 15 +- ITS/AliITSClusterFinderSPD.cxx | 60 +- ITS/AliITSClusterFinderSPD.h | 11 +- ITS/AliITSClusterFinderSSD.cxx | 185 +-- ITS/AliITSClusterFinderSSD.h | 13 +- ITS/AliITSDetType.h | 15 +- ITS/AliITSHuffman.cxx | 45 +- ITS/AliITSHuffman.h | 26 +- ITS/AliITSMap.cxx | 414 +----- ITS/AliITSMap.h | 104 +- ITS/AliITSMapA1.cxx | 184 +++ ITS/AliITSMapA1.h | 66 + ITS/AliITSMapA2.cxx | 258 ++++ ITS/AliITSMapA2.h | 55 + ITS/AliITSRawCluster.cxx | 7 +- ITS/AliITSRawCluster.h | 42 +- ITS/AliITSRecPoint.cxx | 8 + ITS/AliITSRecPoint.h | 3 +- ITS/AliITSclusterSSD.cxx | 44 +- ITS/AliITSclusterSSD.h | 2 +- ITS/AliITSdcsSSD.cxx | 15 +- ITS/AliITSdcsSSD.h | 7 +- ITS/AliITSdictSSD.cxx | 11 +- ITS/AliITSdictSSD.h | 4 - ITS/AliITSdigit.cxx | 26 +- ITS/AliITSdigit.h | 31 +- ITS/AliITSdisplay.cxx | 1791 ++++++++++++++++++++++++++ ITS/AliITSdisplay.h | 157 +++ ITS/AliITSetfSDD.cxx | 146 +-- ITS/AliITSetfSDD.h | 52 +- ITS/AliITSgeom.cxx | 171 ++- ITS/AliITSgeom.h | 21 +- ITS/AliITSgeomSDD.cxx | 3 - ITS/AliITSgeomSDD.h | 4 +- ITS/AliITSgeomSPD.cxx | 3 - ITS/AliITSgeomSPD300.cxx | 6 - ITS/AliITSgeomSPD425.cxx | 6 - ITS/AliITSgeomSSD.cxx | 3 - ITS/AliITSgeomSSD.h | 6 +- ITS/AliITShit.cxx | 3 - ITS/AliITShit.h | 1 - ITS/AliITSmodule.cxx | 21 +- ITS/AliITSpackageSSD.cxx | 96 +- ITS/AliITSpackageSSD.h | 8 +- ITS/AliITSpoints.cxx | 1170 +++++++++++++++++ ITS/AliITSpoints.h | 66 + ITS/AliITSresponse.cxx | 8 + ITS/AliITSresponse.h | 41 +- ITS/AliITSresponseSDD.cxx | 24 +- ITS/AliITSresponseSDD.h | 93 +- ITS/AliITSresponseSPD.h | 25 +- ITS/AliITSresponseSSD.cxx | 6 +- ITS/AliITSresponseSSD.h | 30 +- ITS/AliITSsegmentation.cxx | 8 + ITS/AliITSsegmentation.h | 38 +- ITS/AliITSsegmentationSDD.cxx | 36 +- ITS/AliITSsegmentationSDD.h | 20 +- ITS/AliITSsegmentationSPD.cxx | 33 +- ITS/AliITSsegmentationSPD.h | 12 +- ITS/AliITSsegmentationSSD.cxx | 16 +- ITS/AliITSsegmentationSSD.h | 12 +- ITS/AliITSsimulation.h | 3 +- ITS/AliITSsimulationFastPoints.cxx | 317 ++--- ITS/AliITSsimulationFastPoints.h | 26 +- ITS/AliITSsimulationFastPointsV0.cxx | 184 +++ ITS/AliITSsimulationFastPointsV0.h | 31 + ITS/AliITSsimulationSDD.cxx | 538 ++++---- ITS/AliITSsimulationSDD.h | 45 +- ITS/AliITSsimulationSPD.cxx | 403 +++--- ITS/AliITSsimulationSPD.h | 2 +- ITS/AliITSsimulationSSD.cxx | 116 +- ITS/AliITSsimulationSSD.h | 22 +- ITS/AliITSstatistics.cxx | 83 +- ITS/AliITSstatistics.h | 49 +- ITS/AliITSstatistics2.cxx | 85 +- ITS/AliITSstatistics2.h | 20 +- ITS/AliITStrack.cxx | 8 + ITS/AliITStrack.h | 28 + ITS/AliITSv1.cxx | 130 +- ITS/AliITSv1.h | 14 +- ITS/AliITSv3.cxx | 146 +-- ITS/AliITSv3.h | 18 +- ITS/AliITSv5.cxx | 100 +- ITS/AliITSv5.h | 14 +- ITS/AliITSvtest.cxx | 336 +++++ ITS/AliITSvtest.h | 43 + ITS/AlignITSmacro.C | 110 ++ ITS/AlignITSmacro2.C | 211 +++ ITS/AlignITSmacro3.C | 266 ++++ ITS/AlignITSmacro3A.C | 319 +++++ ITS/AlignITSmacro3B.C | 319 +++++ ITS/AlignITSmacro3C.C | 319 +++++ ITS/AlignITSmacro3R.C | 319 +++++ ITS/AlignITSmacro3Rphi.C | 319 +++++ ITS/AlignITSmacro3Z.C | 319 +++++ ITS/AnalysisITSAlignment.cxx | 1695 ++++++++++++++++++++++++ ITS/AnalysisITSAlignment.h | 48 + ITS/Config.C | 2 +- ITS/ITSDigitsToClusters.C | 128 ++ ITS/ITSHitsToDigits.C | 133 ++ ITS/ITSHitsToFastPoints.C | 81 ++ ITS/ITSLinkDef.h | 114 +- ITS/ITSdigitsTest.C | 6 +- ITS/ITShuffman.C | 69 + ITS/ITSmixedpoints.C | 102 ++ ITS/ITSreadClustTest.C | 105 ++ ITS/ITSreadRecPointsTest.C | 83 ++ ITS/ITSreadTest.C | 124 ++ ITS/ITSstream.C | 68 + ITS/Makefile | 45 +- ITS/SPD_ntuple.C | 329 +++++ ITS/SPDclusterTest.C | 447 +++++++ ITS/vertex.cxx | 718 +++++++++++ ITS/vertex.h | 19 + ITS/vertexmacro.C | 45 + 124 files changed, 14330 insertions(+), 2707 deletions(-) create mode 100644 ITS/AliITSAlignmentModule.cxx create mode 100644 ITS/AliITSAlignmentModule.h create mode 100644 ITS/AliITSAlignmentTrack.cxx create mode 100644 ITS/AliITSAlignmentTrack.h create mode 100644 ITS/AliITSMapA1.cxx create mode 100644 ITS/AliITSMapA1.h create mode 100644 ITS/AliITSMapA2.cxx create mode 100644 ITS/AliITSMapA2.h create mode 100644 ITS/AliITSRecPoint.cxx create mode 100644 ITS/AliITSdisplay.cxx create mode 100644 ITS/AliITSdisplay.h create mode 100644 ITS/AliITSpoints.cxx create mode 100644 ITS/AliITSpoints.h create mode 100644 ITS/AliITSresponse.cxx create mode 100644 ITS/AliITSsegmentation.cxx create mode 100644 ITS/AliITSsimulationFastPointsV0.cxx create mode 100644 ITS/AliITSsimulationFastPointsV0.h create mode 100644 ITS/AliITStrack.cxx create mode 100644 ITS/AliITStrack.h create mode 100644 ITS/AliITSvtest.cxx create mode 100644 ITS/AliITSvtest.h create mode 100644 ITS/AlignITSmacro.C create mode 100644 ITS/AlignITSmacro2.C create mode 100644 ITS/AlignITSmacro3.C create mode 100644 ITS/AlignITSmacro3A.C create mode 100644 ITS/AlignITSmacro3B.C create mode 100644 ITS/AlignITSmacro3C.C create mode 100644 ITS/AlignITSmacro3R.C create mode 100644 ITS/AlignITSmacro3Rphi.C create mode 100644 ITS/AlignITSmacro3Z.C create mode 100644 ITS/AnalysisITSAlignment.cxx create mode 100644 ITS/AnalysisITSAlignment.h create mode 100644 ITS/ITSDigitsToClusters.C create mode 100644 ITS/ITSHitsToDigits.C create mode 100644 ITS/ITSHitsToFastPoints.C create mode 100644 ITS/ITShuffman.C create mode 100644 ITS/ITSmixedpoints.C create mode 100644 ITS/ITSreadClustTest.C create mode 100644 ITS/ITSreadRecPointsTest.C create mode 100644 ITS/ITSreadTest.C create mode 100644 ITS/ITSstream.C create mode 100644 ITS/SPD_ntuple.C create mode 100644 ITS/SPDclusterTest.C create mode 100755 ITS/vertex.cxx create mode 100755 ITS/vertex.h create mode 100755 ITS/vertexmacro.C diff --git a/ITS/AliITS.cxx b/ITS/AliITS.cxx index fcb1c276724..8525fde4de0 100644 --- a/ITS/AliITS.cxx +++ b/ITS/AliITS.cxx @@ -15,24 +15,6 @@ /* $Log$ -Revision 1.15 2000/06/28 14:41:12 fca -Corrections to the custom Streamer - -Revision 1.14 2000/06/15 09:27:52 barbera -Problems with the HP compiler fixed - -Revision 1.13 2000/06/13 15:32:44 nilsen -fix compilation error on HP and DEC unix. - -Revision 1.12 2000/06/12 23:43:16 nilsen -New ITS code replacing the old structure and simulations code. - -Revision 1.9.2.8 2000/06/12 18:05:59 barbera -fixed posible compilation errors on HP unix - -Revision 1.9.2.7 2000/06/11 20:20:18 barbera -New AliITS base clase for the new structure. - Revision 1.9.2.3 2000/02/02 13:42:09 barbera fixed AliITS.cxx for new AliRun structure. Added ITS hits list to list of hits which will have their track numbers updated @@ -104,7 +86,6 @@ the AliITS class. #include #include #include -#include #include #include @@ -113,16 +94,16 @@ the AliITS class. #include "AliRun.h" #include "AliITS.h" #include "AliITSMap.h" +#include "AliITSDetType.h" #include "AliITSClusterFinder.h" #include "AliITSsimulation.h" -#include "AliITSsimulationFastPoints.h" #include "AliITSsegmentationSPD.h" #include "AliITSresponseSPD.h" #include "AliITSsegmentationSDD.h" #include "AliITSresponseSDD.h" #include "AliITSsegmentationSSD.h" #include "AliITSresponseSSD.h" -//#include "AliITStrack.h" + ClassImp(AliITS) @@ -140,13 +121,14 @@ AliITS::AliITS() : AliDetector() { fIshunt = 0; fEuclidOut = 0; + + //fNDetTypes = fgkNTYPES; fIdN = 0; fIdName = 0; fIdSens = 0; fITSmodules = 0; // fDetTypes = 0; - SetNDetTypes(); // fDtype = 0; fNdtype = 0; @@ -154,6 +136,7 @@ AliITS::AliITS() : AliDetector() { fNctype = 0; fRecPoints = 0; fNRecPoints = 0; + fTreeC = 0; // fITSgeom=0; } @@ -176,16 +159,19 @@ AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){ fHits = new TClonesArray("AliITShit", 1560); gAlice->AddHitList(fHits); - SetNDetTypes(); + //fNDetTypes = fgkNTYPES; + + fNdtype = new Int_t[fgkNTYPES]; + fDtype = new TObjArray(fgkNTYPES); + + fNctype = new Int_t[fgkNTYPES]; + fCtype = new TObjArray(fgkNTYPES); - fNdtype = 0; - fDtype = 0; - fCtype = 0; - fNctype = 0; fRecPoints = 0; fNRecPoints = 0; + fTreeC = 0; fITSmodules = 0; @@ -195,38 +181,38 @@ AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){ fIdName = 0; fIdSens = 0; - fDetTypes = new TObjArray(fNDetTypes); + fDetTypes = new TObjArray(fgkNTYPES); Int_t i; - for(i=0;iGetModuleIndex(4,fITSgeom->GetNladders(4), fITSgeom->GetNdetectors(4)); for(i=0;iGetEntriesFast();i++){ + if(!fITSmodules->At(i)) continue; if(iAt(i); + delete (AliITSmodule *) fITSmodules->At(i); else if(iAt(i); + delete (AliITSmodule *) fITSmodules->At(i); else - delete (AliITSmodule *) fITSmodules->At(i); + delete (AliITSmodule *) fITSmodules->At(i); } // end for i }// end if fITSmodules!=0 @@ -269,13 +256,13 @@ AliITS::~AliITS(){ // Int_t i; if(fDtype) { - for(i=0;iClassNames(digit,cluster); @@ -363,13 +350,11 @@ void AliITS::AddRealDigit(Int_t id, Int_t *digits) } //_____________________________________________________________________________ -void AliITS::AddDigit(Int_t id, AliITSdigit *d) +void AliITS::AddSimDigit(Int_t id, AliITSdigit *d) { // add a simulated digit - // should have ctors of type AliITSdigitSDD(const AliITSdigitSDD &) - TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]); switch(id) @@ -388,7 +373,7 @@ void AliITS::AddDigit(Int_t id, AliITSdigit *d) } //_____________________________________________________________________________ -void AliITS::AddDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,Float_t *charges){ +void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,Int_t *hits,Float_t *charges){ // add a simulated digit to the list @@ -396,13 +381,13 @@ void AliITS::AddDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,Float_t switch(id) { case 0: - new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks); + new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits); break; case 1: - new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,charges); + new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,hits,charges); break; case 2: - new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks); + new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits); break; } @@ -414,8 +399,6 @@ void AliITS::AddCluster(Int_t id, AliITSRawCluster *c) // add a cluster to the list - // should have ctors of type AliITSRawClusterSDD(const AliITSRawClusterSDD &) - TClonesArray &lcl = *((TClonesArray*)(*fCtype)[id]); switch(id) @@ -455,7 +438,7 @@ void AliITS::ResetDigits() if (!fDtype) return; Int_t i; - for(i=0;iClear(); if (fNdtype) fNdtype[i]=0; } @@ -467,10 +450,11 @@ void AliITS::ResetDigits(Int_t i) // // Reset number of digits and the digits array for this branch // - if ((*fDtype)[i]) ((TClonesArray*)(*fDtype)[i])->Clear(); - if (fNdtype) fNdtype[i]=0; - + if ((*fDtype)[i]) ((TClonesArray*)(*fDtype)[i])->Clear(); + if (fNdtype) fNdtype[i]=0; } + + //____________________________________________ void AliITS::ResetClusters() { @@ -479,12 +463,13 @@ void AliITS::ResetClusters() // Int_t i; - for(i=0;iClear(); if (fNctype) fNctype[i]=0; } } + //____________________________________________ void AliITS::ResetClusters(Int_t i) { @@ -535,7 +520,6 @@ void AliITS::Init(){ SetDefaults(); Int_t i; - printf("\n"); for(i=0;i<35;i++) printf("*"); printf(" ITS_INIT "); @@ -565,8 +549,8 @@ void AliITS::SetDefaults() if (!iDetType->GetSegmentationModel()) SetSegmentationModel(0,seg0); if (!iDetType->GetResponseModel()) SetResponseModel(0,resp0); // set digit and raw cluster classes to be used - const char *kData=resp0->DataType(); - if (strstr(kData,"real")) { + const char *kData0=resp0->DataType(); + if (strstr(kData0,"real")) { iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD"); } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD"); @@ -576,9 +560,9 @@ void AliITS::SetDefaults() iDetType=DetType(1); if (!iDetType->GetSegmentationModel()) SetSegmentationModel(1,seg1); if (!iDetType->GetResponseModel()) SetResponseModel(1,resp1); - kData=resp1->DataType(); - Option_t *opt=resp1->ZeroSuppOption(); - if ((!strstr(opt,"2D")) && (!strstr(opt,"1D")) || strstr(kData,"real") ) { + const char *kData1=resp1->DataType(); + const char *kopt=resp1->ZeroSuppOption(); + if ((!strstr(kopt,"2D")) && (!strstr(kopt,"1D")) || strstr(kData1,"real") ) { iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD"); } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD"); @@ -588,18 +572,30 @@ void AliITS::SetDefaults() iDetType=DetType(2); if (!iDetType->GetSegmentationModel()) SetSegmentationModel(2,seg2); if (!iDetType->GetResponseModel()) SetResponseModel(2,resp2); - kData=resp2->DataType(); - if (strstr(kData,"real")) { + const char *kData2=resp2->DataType(); + if (strstr(kData2,"real")) { iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD"); } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD"); - if (fNDetTypes>3) { + if (fgkNTYPES>3) { Warning("SetDefaults","Only the three basic detector types are initialised!"); } } +//_____________________________________________________________________________ +void AliITS::SetDefaultSimulation() +{ + // to be written + +} +//_____________________________________________________________________________ +void AliITS::SetDefaultClusterFinders() +{ + // to be written + +} //_____________________________________________________________________________ void AliITS::MakeTreeC(Option_t *option) @@ -616,8 +612,8 @@ void AliITS::MakeTreeC(Option_t *option) // one branch for Clusters per type of detector Int_t i; - for(i=0; iBranch(branchname,&((*fCtype)[i]), buffersize); @@ -649,10 +645,10 @@ void AliITS::GetTreeC(Int_t event) TBranch *branch; if (fTreeC) { Int_t i; - for(i=0; iGetBranch(branchname); if (branch) branch->SetAddress(&((*fCtype)[i])); } @@ -680,25 +676,23 @@ void AliITS::MakeBranch(Option_t* option){ char *det[3] = {"SPD","SDD","SSD"}; - char *kDigclass; - char *kClclass; + char digclass[40]; + char clclass[40]; Int_t i; - for(i=0; iGetClassNames(kDigclass,kClclass); - //printf("i, digclass, recclass %d %s %s\n",i,kDigclass,kClclass); + iDetType->GetClassNames(digclass,clclass); + //printf("i, digclass, recclass %d %s %s\n",i,digclass,clclass); // digits - (*fDtype)[i] = new TClonesArray(kDigclass,100); - fNdtype[i]=0; + (*fDtype)[i] = new TClonesArray(digclass,10000); // clusters - (*fCtype)[i] = new TClonesArray(kClclass,100); - fNctype[i]=0; + (*fCtype)[i] = new TClonesArray(clclass,10000); } - for(i=0; iTreeD()) { @@ -710,7 +704,7 @@ void AliITS::MakeBranch(Option_t* option){ // only one branch for rec points for all detector types sprintf(branchname,"%sRecPoints",GetName()); - fRecPoints=new TClonesArray("AliITSRecPoint",1000); + fRecPoints=new TClonesArray("AliITSRecPoint",10000); if (fRecPoints && gAlice->TreeR()) { gAlice->TreeR()->Branch(branchname,&fRecPoints, buffersize); @@ -737,8 +731,8 @@ void AliITS::SetTreeAddress() Int_t i; if (treeD) { - for(i=0; iGetBranch(branchname); @@ -764,6 +758,11 @@ void AliITS::InitModules(Int_t size,Int_t &nmodules){ //initialize the modules array + if(fITSmodules){ + //this->ClearModules(); + delete fITSmodules; + } + Int_t nl,indexMAX,index; Int_t indSPD,indSDD; @@ -796,7 +795,7 @@ void AliITS::InitModules(Int_t size,Int_t &nmodules){ } //____________________________________________________________________________ -void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t lastev,Int_t nmodules,Option_t *option,Text_t *filename){ +void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,Option_t *option,Text_t *filename){ // fill the modules with the sorted by module hits; add hits from background // if option=Add @@ -806,10 +805,10 @@ void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t lastev,Int_t nmodules,Opti static Bool_t first=kTRUE; static TFile *file; - char *add = strstr(option,"Add"); + char *addBgr = strstr(option,"Add"); - if (add ) { + if (addBgr ) { if(first) { cout<<"filename "<GetEvent(evnt); if(npart<=0) return; TClonesArray *itsHits = this->Hits(); @@ -874,19 +861,11 @@ void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t lastev,Int_t nmodules,Opti iTH->GetEvent(t); Int_t nhits = itsHits->GetEntriesFast(); if (!nhits) continue; - // cout << nhits << " hits in track " << t << endl; for(h=0; hUncheckedAt(h); itsHit->GetDetectorID(lay,lad,det); index = fITSgeom->GetModuleIndex(lay,lad,det); mod = this->GetModule(index); - if (add) { - xhit[index][signal[index]]=itsHit->fX; - yhit[index][signal[index]]=itsHit->fY; - signal[index]++; - if (signal[index] >4) - printf("index,nsignal %d %d\n",index,signal[index]); - } if(lay == 1 || lay == 2) mod->AddHit((AliITShit *) itsHit,t,h); else if(lay == 3 || lay == 4) @@ -901,14 +880,14 @@ void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t lastev,Int_t nmodules,Opti // open the file with background - if (add ) { - Int_t track,i,isig; + if (addBgr ) { + Int_t track,i; ntracks =(Int_t)trH1->GetEntries(); //printf("background - ntracks1 %d\n",ntracks); //printf("background - Start loop over tracks \n"); // Loop over tracks - for(track=0; trackClear(); trH1->GetEvent(track); @@ -920,18 +899,6 @@ void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t lastev,Int_t nmodules,Opti index = fITSgeom->GetModuleIndex(lay,lad,det); mod = this->GetModule(index); - Float_t xbgr=itsHit->fX; - Float_t ybgr=itsHit->fY; - Float_t ebgr=itsHit->GetIonization(); - Bool_t cond=kFALSE; - - for(isig =0; isig < signal[index]; isig++) { - Float_t dist= - (xbgr-xhit[index][isig])*(xbgr-xhit[index][isig]) - +(ybgr-yhit[index][isig])*(ybgr-yhit[index][isig]); - if (dist<0.2&& ebgr!=0) cond=kTRUE; // check this number for ITS! - } - if (!cond) continue; if(lay == 1 || lay == 2) mod->AddHit((AliITShit *) itsHit,track,i); else if(lay == 3 || lay == 4) @@ -949,38 +916,27 @@ void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t lastev,Int_t nmodules,Opti TFile *fileAli=0; if (fAli) fileAli =fAli->GetCurrentFile(); - //printf("fAli, file %p %p\n",fAli,file); file->cd(); } // end if add - - for(i=0;iPrint(); } //____________________________________________________________________________ -void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t lastev,Int_t size, -Option_t *option,Option_t *opt,Text_t *filename) +void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size, Option_t *option, Option_t *opt,Text_t *filename) { // keep galice.root for signal and name differently the file for // background when add! otherwise the track info for signal will be lost ! char *all = strstr(opt,"All"); char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")}; - //printf("Det 1 2 3 %s %s %s \n",det[0],det[1],det[2]); Int_t nmodules; InitModules(size,nmodules); - FillModules(evNumber,bgrev,lastev,nmodules,option,filename); - //printf("nmodules %d\n",nmodules); + FillModules(evNumber,bgrev,nmodules,option,filename); TBranch *branch; AliITSsimulation* sim; @@ -989,8 +945,7 @@ Option_t *option,Option_t *opt,Text_t *filename) AliITSgeom *geom = GetITSgeom(); Int_t id,module; - for(id=0;id<3;id++) { - //printf("id %d All %s det[id] %s \n",id,all,det[id]); + for (id=0;idUncheckedAt(id); AliITSDetType *iDetType=DetType(id); @@ -998,11 +953,11 @@ Option_t *option,Option_t *opt,Text_t *filename) if (!sim) { Error("HitsToDigits","The simulation class was not instantiated!"); exit(1); - // or SetDefaultSimulation(id,iDetType*); + // or SetDefaultSimulation(); } Int_t first = geom->GetStartDet(id); Int_t last = geom->GetLastDet(id); - //printf("det type %d first, last %d %d \n",id,first,last); + printf("det type %d first, last %d %d \n",id,first,last); for(module=first;module<=last;module++) { AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module); sim->DigitiseModule(mod,module,evNumber); @@ -1015,10 +970,10 @@ Option_t *option,Option_t *opt,Text_t *filename) } // loop over modules } // loop over detector types - ClearModules(); - //Int_t nentries=(Int_t)gAlice->TreeD()->GetEntries(); + Int_t nentries=(Int_t)gAlice->TreeD()->GetEntries(); + printf("nentries in TreeD %d\n",nentries); char hname[30]; sprintf(hname,"TreeD%d",evNumber); @@ -1032,6 +987,7 @@ Option_t *option,Option_t *opt,Text_t *filename) //____________________________________________________________________________ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt) { + // cluster finding and reconstruction of space points char *all = strstr(opt,"All"); char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")}; @@ -1050,7 +1006,7 @@ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt) AliITSgeom *geom = GetITSgeom(); Int_t id,module; - for(id=0;idUncheckedAt(id); AliITSDetType *iDetType=DetType(id); @@ -1058,15 +1014,13 @@ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt) if (!rec) { Error("DigitsToRecPoints","The cluster finder class was not instantiated!"); exit(1); - // or SetDefaultClusterFinder(id,iDetType*); + // or SetDefaultClusterFinders(); } TClonesArray *itsDigits = this->DigitsAddress(id); Int_t first = geom->GetStartDet(id); Int_t last = geom->GetLastDet(id); - //printf("det type %d first, last %d %d \n",id,first,last); for(module=first;module<=last;module++) { - //printf("AliITS: module=%d\n",module); this->ResetDigits(); if (all) gAlice->TreeD()->GetEvent(lastentry+module); else gAlice->TreeD()->GetEvent(lastentry+(module-first)); @@ -1083,9 +1037,9 @@ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt) } // loop over detector types - //Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries(); - - //Int_t ncentries=(Int_t)TC->GetEntries(); + Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries(); + Int_t ncentries=(Int_t)iTC->GetEntries(); + printf(" nentries ncentries %d %d\n", nentries, ncentries); char hname[30]; sprintf(hname,"TreeR%d",evNumber); @@ -1100,7 +1054,7 @@ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt) //____________________________________________________________________________ -void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t lastev,Int_t size, +void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size, Option_t *option,Option_t *opt,Text_t *filename) { // keep galice.root for signal and name differently the file for @@ -1110,23 +1064,40 @@ Option_t *option,Option_t *opt,Text_t *filename) char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")}; Int_t nmodules; - InitModules(size,nmodules); - FillModules(evNumber,bgrev,lastev,nmodules,option,filename); - - static AliITSsimulationFastPoints* sim=0; - if (!sim) sim = new AliITSsimulationFastPoints(); + InitModules(size,nmodules); + FillModules(evNumber,bgrev,nmodules,option,filename); + AliITSsimulation* sim; AliITSgeom *geom = GetITSgeom(); + TRandom *random=new TRandom[9]; + random[0].SetSeed(111); + random[1].SetSeed(222); + random[2].SetSeed(333); + random[3].SetSeed(444); + random[4].SetSeed(555); + random[5].SetSeed(666); + random[6].SetSeed(777); + random[7].SetSeed(888); + random[8].SetSeed(999); + + Int_t id,module; - for(id=0;id<3;id++) { + for (id=0;idGetSimulationModel(); + if (!sim) { + Error("HitsToFastPoints","The simulation class was not instantiated!"); + exit(1); + // or SetDefaultSimulation(); + } Int_t first = geom->GetStartDet(id); Int_t last = geom->GetLastDet(id); for(module=first;module<=last;module++) { AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module); - sim->CreateFastRecPoints(mod); + sim->CreateFastRecPoints(mod,module,random); gAlice->TreeR()->Fill(); ResetRecPoints(); } // loop over modules @@ -1143,85 +1114,62 @@ Option_t *option,Option_t *opt,Text_t *filename) // reset tree gAlice->TreeR()->Reset(); + delete [] random; + } -//______________________________________________________________________________ -void AliITS::Streamer(TBuffer &R__b) -{ +//____________________________________________________________________________ +void AliITS::Streamer(TBuffer &R__b){ // Stream an object of class AliITS. - Int_t i, j, l; + Int_t i; if (R__b.IsReading()) { Version_t R__v = R__b.ReadVersion(); if (R__v) { AliDetector::Streamer(R__b); + R__b >> fIdN; + R__b.ReadArray(fIdSens); + for(i=0;i> fITSgeom; R__b >> fITSmodules; R__b >> fEuclidOut; - R__b >> fIdN; - delete []fIdSens; - fIdSens = new Int_t[fIdN]; - R__b.ReadFastArray(fIdSens,fIdN); - if(fIdName!=0) delete[] fIdName; - fIdName = new char*[fIdN]; - for(i=0;i> l; - fIdName[i] = new char[l+1]; // add room for null character. - for(j=0;j> fIdName[i][j]; - fIdName[i][l] = '\0'; // Null terminate this string. - } // end for i - //R__b.ReadArray(fIdName); R__b >> fMajorVersion; R__b >> fMinorVersion; R__b >> fDetTypes; - R__b >> fNDetTypes; R__b >> fDtype; delete []fNdtype; - fNdtype = new Int_t[fNDetTypes]; - R__b.ReadFastArray(fNdtype,fNDetTypes); + fNdtype = new Int_t[fgkNTYPES]; + R__b.ReadFastArray(fNdtype,fgkNTYPES); R__b >> fCtype; delete []fNctype; - fNctype = new Int_t[fNDetTypes]; - R__b.ReadFastArray(fNctype,fNDetTypes); + fNctype = new Int_t[fgkNTYPES]; + R__b.ReadFastArray(fNctype,fgkNTYPES); R__b >> fRecPoints; R__b >> fNRecPoints; - R__b >> fTracks; R__b >> fTreeC; } // end if R__v } else { // writing R__b.WriteVersion(AliITS::IsA()); AliDetector::Streamer(R__b); + R__b << fIdN; + R__b.WriteArray(fIdSens,fIdN); + for(i=0;iStreamer(R__b); R__b << fNRecPoints; - R__b << fTracks; - // fTracks->Streamer(R__b); R__b << fTreeC; } // end if + } -ClassImp(AliITSRecPoint) -ClassImp(AliITSsegmentation) -ClassImp(AliITSresponse) -//ClassImp(AliITStrack) diff --git a/ITS/AliITS.h b/ITS/AliITS.h index cfc4bd50b0f..e4d71f5c3f0 100644 --- a/ITS/AliITS.h +++ b/ITS/AliITS.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -19,17 +20,15 @@ #include "AliITSgeom.h" #include "AliITSsegmentation.h" #include "AliITSresponse.h" -#include "AliITSDetType.h" #include "AliITShit.h" #include "AliITSdigit.h" #include "AliITSmodule.h" #include "AliITSRecPoint.h" #include "AliITSRawCluster.h" - +class AliITSDetType; class AliITSsimulation; class AliITSClusterFinder; -//class AliITStrack; class AliITS : public AliDetector { @@ -42,13 +41,11 @@ class AliITS : public AliDetector { virtual void AddHit(Int_t track, Int_t *vol, Float_t *hits); virtual void AddRealDigit(Int_t branch, Int_t *digits); - virtual void AddDigit(Int_t branch, AliITSdigit *d); - virtual void AddDigit(Int_t branch,Float_t phys,Int_t* digits, Int_t* tracks, Float_t* trkcharges); + virtual void AddSimDigit(Int_t branch, AliITSdigit *d); + virtual void AddSimDigit(Int_t branch,Float_t phys,Int_t* digits,Int_t* tracks,Int_t *hits,Float_t* trkcharges); // virtual void AddCluster(Int_t branch, AliITSRawCluster *c); virtual void AddRecPoint(const AliITSRecPoint &p); - virtual void AddTrack(Float_t* tracks) {} -// virtual void AddTrack(const AliITStrack&) {} virtual void ResetDigits(); // depending on how the virtual void ResetDigits(Int_t branch); // tree will be filled only @@ -56,16 +53,15 @@ class AliITS : public AliDetector { virtual void ResetClusters(Int_t branch); // the pair will be kept virtual void ResetRecPoints(); - virtual void BuildGeometry() {} - virtual void CreateGeometry() {} - virtual void CreateMaterials() {} - + // get geometry version - detailed (major) or coarse (minor) void GetGeometryVersion(Int_t &a,Int_t &b) const {a = fMajorVersion;b=fMinorVersion;return;} virtual Int_t IsVersion() const {return 1;} Int_t DistancetoPrimitive(Int_t px, Int_t py); virtual void Init(); virtual void SetDefaults(); + virtual void SetDefaultSimulation(); + virtual void SetDefaultClusterFinders(); // create separate tree for clusters - declustering refining virtual void MakeTreeC(Option_t *option="C"); void GetTreeC(Int_t event); @@ -75,26 +71,24 @@ class AliITS : public AliDetector { virtual void StepManager() {} // sort hits by module virtual void InitModules(Int_t size,Int_t &nmodules); - virtual void FillModules(Int_t evnt,Int_t bgrev,Int_t lastev, + virtual void FillModules(Int_t evnt,Int_t bgrev, Int_t nmodules,Option_t *opt,Text_t *filename); virtual void ClearModules(); // Digitisation - void HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t lastev,Int_t size, + void HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size, Option_t *add, Option_t *det, Text_t *filename); // Reconstruct hits void DigitsToRecPoints(Int_t evNumber,Int_t lastEntry,Option_t *det); // Fast simulation of space points from hits - void HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t lastev,Int_t size, + void HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size, Option_t *add, Option_t *det, Text_t *filename); - - // Write digits into raw data format virtual void Digits2RawData() {} + // Decode raw data and store digits + virtual void RawData2Digits() {} // Configuration Methods (per detector type ) - // Set number of detector types - virtual void SetNDetTypes(Int_t ndtypes=3) {fNDetTypes=ndtypes;} // Set response virtual void SetResponseModel(Int_t id, AliITSresponse *response); // Set segmentation @@ -104,13 +98,15 @@ class AliITS : public AliDetector { // Set reconstruction virtual void SetReconstructionModel(Int_t id, AliITSClusterFinder *rec); // Set class names for digit and rec point - virtual void SetClasses(Int_t id, char* digit, char* cluster); + virtual void SetClasses(Int_t id, const char *digit, const char *cluster); // Getters // ITS geometry functions virtual AliITSgeom *GetITSgeom() const {return fITSgeom;} + // return pointer to the array of modules virtual TObjArray *GetModules() const {return fITSmodules;} + // return pointer to a particular module AliITSmodule *GetModule(Int_t index) {return (AliITSmodule *) (fITSmodules->At(index));} @@ -127,44 +123,44 @@ class AliITS : public AliDetector { // Return pointer to rec points TClonesArray *RecPoints() {return fRecPoints;} - // Return pointer to tracks - TClonesArray *Tracks() {return fTracks;} // Return pointer to DetType #id AliITSDetType *DetType(Int_t id); - Int_t NDetTypes() {return fNDetTypes;} + //Int_t NDetTypes() {return fNDetTypes;} // Return pointer to the tree of clusters TTree *TreeC() {return fTreeC;} + protected: + static const Int_t fgkNTYPES=3; // Number of detector types + AliITSgeom *fITSgeom; // Pointer to ITS geometry TObjArray *fITSmodules; // Pointer to ITS modules Bool_t fEuclidOut; // Flag to write out geometry - //in euclid format + // in euclid format Int_t fIdN; // the number of layers Int_t *fIdSens; //[fIdN] layer identifier - char **fIdName; //layer identifier + TString *fIdName; //[fIdN] layer identifier // Geometry and Stepmanager version numbers used. Int_t fMajorVersion,fMinorVersion; //detailed and coarse(minor) versions // // + + // Int_t fNDetTypes; //Number of detector types TObjArray *fDetTypes; // List of detector types - Int_t fNDetTypes; // Number of Detector types - TObjArray *fDtype; // List of digits - Int_t *fNdtype; //[fNDetTypes] Number of digits per type of + TObjArray *fDtype; //[fgkNTYPES] List of digits + Int_t *fNdtype; //[fgkNTYPES] Number of digits per type of // detector - TObjArray *fCtype; // List of clusters - Int_t *fNctype; //[fNDetTypes] Number of clusters per type + TObjArray *fCtype; //[fgkNTYPES] List of clusters + Int_t *fNctype; //[fgkNTYPES] Number of clusters per type // of detector - TClonesArray *fRecPoints; // List of reconstructed points Int_t fNRecPoints; // Number of rec points - TClonesArray *fTracks; // List of reconstructed tracks TTree *fTreeC; // Tree for raw clusters diff --git a/ITS/AliITSAlignmentModule.cxx b/ITS/AliITSAlignmentModule.cxx new file mode 100644 index 00000000000..0f7e4e7b41a --- /dev/null +++ b/ITS/AliITSAlignmentModule.cxx @@ -0,0 +1,454 @@ +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ +/* $Id$ */ +/* $Author$ */ +/* $Date$ */ +/* $Name$ */ +/* $Header$ */ +/* + $Log$ + Revision 1.1.2.3 2000/06/04 16:35:09 nilsen + One more try to fix log comments. + + Revision 1.1.2.2 2000/03/04 23:39:36 nilsen + Fixed the logs??? + */ +/* Revision 1.1.2.1 2000/03/02 20:12:23 nilsen */ +/* A new class usefull for ITS detector Alignment Studdies */ +/* */ +/* $Revision$ */ + +// Standard C & C++ libraries +#include + +// Standard Root Libraries +#include + +// ITS libraries +#include "AliITSgeom.h" +#include "AliITSAlignmentTrack.h" +#include "AliITSAlignmentModule.h" + +ClassImp(AliITSAlignmentModule) + +//______________________________________________________________________ +AliITSAlignmentModule::AliITSAlignmentModule(){ + + findex = -1; + flay = -1; + flad = -1; + fdet = -1; + fx0[0] = 0.0; + fx0[1] = 0.0; + fx0[2] = 0.0; + fangles[0] = 0.0; + fangles[1] = 0.0; + fangles[2] = 0.0; + fM[0][0] = 0.0; + fM[0][1] = 0.0; + fM[0][2] = 0.0; + fM[1][0] = 0.0; + fM[1][1] = 0.0; + fM[1][2] = 0.0; + fM[2][0] = 0.0; + fM[2][1] = 0.0; + fM[2][2] = 0.0; + ftrksM =0; + fChi2 = 0.0; +} +//______________________________________________________________________ +AliITSAlignmentModule::AliITSAlignmentModule(Int_t index,AliITSgeom *gm, + Int_t ntrk,AliITSAlignmentTrack *trk){ + Float_t x,y,z,n; + Int_t i,j; + + findex = index; + gm->GetModuleId(index,flay,flad,fdet); + gm->GetRotMatrix(index,(Double_t *) &(fM[0][0])); + gm->GetTrans(flay,flad,fdet,x,y,z); + fx0[0] = (Double_t )x; + fx0[1] = (Double_t )y; + fx0[2] = (Double_t )z; + gm->GetAngles(flay,flad,fdet,x,y,z); + fangles[0] = (Double_t )x; + fangles[1] = (Double_t )y; + fangles[2] = (Double_t )z; + ftrksM = new TObjArray(); + fChi2 = 0.0; + + for(i=0;iAddAtFree((TObject *) &trk[i]); + break; // break out of the j loop + } // end if + } // end for j + } // end for i +} +//______________________________________________________________________ +Double_t AliITSAlignmentModule::ComputeChi2(){ + Float_t n; + Int_t i,j,ntrk,ntr; + + ntrk = ftrksM->GetEntriesFast(); + fChi2 = 0.0; + for(i=0;iAt(i)))->GetNumberOfClustersSl(); + for(j=0;jAt(i)))-> + GetChi2(); + n++; + } // end for j + if(n==0){ + fChi2 = -1.0; + }else{ + fChi2 /= (Double_t) n; + } // end if n==0 + } // end for i + return fChi2; +} +//______________________________________________________________________ +void AliITSAlignmentModule::lnsrch(Int_t npar,Double_t *xold,Double_t fold, + Double_t *g,Double_t *p,Double_t *x, + Double_t &f, Double_t stpmax,Int_t &check){ + Double_t ALF = 1.0e-4, TOLX = 1.0E-7; + + Int_t i; + Double_t a,alam,alam2=0.0,alamin,b,disc,f2=0.0,rhs1,rhs2,slope,sum,temp, + test,tmplam; + + check = 0; + for(sum=0.0,i=0;istpmax) for(i=0;i=0.0) printf("Error: round off problem in lnsrch.\n"); + test = 0.0; + for(i=0;i test) test = temp; + } // end for i + alamin = TOLX/test; + alam = 1.0; + for(;;){ + for(i=0;i 0.5*alam) tmplam = 0.5*alam; + } // end if alam == 1.0 + } // end if alam < alamin + alam2 = alam; + f2 = f; + alam = TMath::Max(tmplam,0.1*alam); + } // end for ever loop + +} +//______________________________________________________________________ +void AliITSAlignmentModule::MRVMminimization(Int_t npar,Double_t *p, + Double_t &fret,Double_t gtol, + Int_t &iter){ + Int_t ITMAX = 200; + Double_t EPS = 3.0e-8, TOLX = 4.0*EPS, STPMX = 100.0; + + Int_t check,i,its,j; + Double_t den,fac,fad,fae,fp,stpmax,sum=0.0,sumdg,sumxi,temp,test; + Double_t *dg,*g,*hdg,**hessin,*pnew,*xi; + + // allocate space. + dg = new Double_t[npar]; + g = new Double_t[npar]; + hdg = new Double_t[npar]; + hessin = new Double_t * [npar]; + for(i=0;i test) test = temp; + } // end for i + if(testtest) test=temp; + } // end for i + if(testTMath::Sqrt(EPS*sumdg*sumxi)){ + fac = 1.0/fac; + fad = 1.0/fae; + for(i=0;i... + for(i=0;iGetEntriesFast();i++) { + tr = (AliITSAlignmentTrack *)(ftrksM->At(i)); + for(j=0;jGetNumberOfClustersSl();j++){ + tr->GetIndex(j,indx); + if(indx==findex){ + n++; + tr->GetPointG(j,(Double_t *)xi); + tr->func(xi,xo); + tr->GetPointL(j,(Double_t *)xi); + tr->GetErrorG(j,(Double_t **)Ex); + LtoG(xi,xg); + for(k=0;k<3;k++)for(l=0;l<3;l++) + chi += (xg[k] - xo[k])*Ex[k][l]*(xg[l]-xo[l]); + } // end if indx==findex + } // end for j + } // end for i + if(n<7) return chi; + return chi/(Double_t)(n-6); +} +//______________________________________________________________________ +void AliITSAlignmentModule::dChi2(Double_t p[],Double_t dChi2[]){ + Int_t i,j,k,l,m,n=0,indx; + Double_t chi[6]={0.0,0.0,0.0,0.0,0.0,0.0},xo[3],xi[3],xg[3],Ex[3][3]; + Double_t dxdp[3][6],fMx[3][3],fMy[3][3],fMz[3][3]; + AliITSAlignmentTrack *tr; + + for(i=0;i<3;i++) fx0[i] = p[i]; + SetByAngles(&(p[3])); + dfMdthx(fMx); + dfMdthy(fMy); + dfMdthz(fMz); + for(i=0;i<3;i++)for(j=0;j<6;j++) dxdp[i][j] = 0.0; + dxdp[0][0] = 1.0; // dx/dx + dxdp[1][1] = 1.0; // dy/dy + dxdp[2][2] = 1.0; // dz/dz + + for(i=0;iGetEntriesFast();i++) { + tr = (AliITSAlignmentTrack *)(ftrksM->At(i)); + for(j=0;jGetNumberOfClustersSl();j++){ + tr->GetIndex(j,indx); + if(indx==findex){ + n++; + tr->GetPointG(j,(Double_t *)xi); + tr->func(xi,xo); + tr->GetPointL(j,(Double_t *)xi); + tr->GetErrorG(j,(Double_t **)Ex); + LtoG(xi,xg); + for(m=0;m<3;m++) for(k=0;k<3;k++){ + dxdp[m][3] += fMx[m][k]*xi[k]; + dxdp[m][4] += fMy[m][k]*xi[k]; + dxdp[m][5] += fMz[m][k]*xi[k]; + } // end for m + for(m=0;m<6;m++){ + for(k=0;k<3;k++)for(l=0;l<3;l++) + chi[m] += (xg[k] - xo[k])*Ex[k][l]*dxdp[l][m]; + } // end for m + } // end if indx==findex + } // end for j + } // end for i + if(n<7) return ; + for(m=0;m<6;m++) chi[m] /= (Double_t)(n-6); + return; +} +//______________________________________________________________________ +void AliITSAlignmentModule::AlignModule(){ + static Int_t npar=6; + Int_t iter,i; + //Double_t p[npar],fret,gtol=1.0E-5; + Double_t p[6],fret,gtol=1.0E-5; + + for(i=0;i<3;i++) {p[i] = fx0[i]; p[i+3] = fangles[i];} + MRVMminimization(npar,(Double_t *)p,fret,gtol,iter); + for(i=0;i<3;i++) {fx0[i] = p[i]; fangles[i] = p[i+3];} + printf("AlignModule #%d:Xt=(%e,%e,%e) cm angles=(%e,%e,%e)rad," + " Chi2=%e loops=%d\n",findex, + fx0[0],fx0[1],fx0[2],fangles[0],fangles[1],fangles[2],fret,iter); +} +//______________________________________________________________________ +void AliITSAlignmentModule::Streamer(TBuffer &R__b){ + // Stream an object of class AliITSAlignmentModule. + + if (R__b.IsReading()) { + Version_t R__v = R__b.ReadVersion(); if (R__v) { } + TObject::Streamer(R__b); + R__b >> findex; + R__b >> flay; + R__b >> flad; + R__b >> fdet; + R__b >> ftrksM; + R__b >> fChi2; +// R__b.ReadStaticArray(fx0); +// R__b.ReadStaticArray((double*)fM); +// R__b.ReadStaticArray(fangles); + } else { + R__b.WriteVersion(AliITSAlignmentModule::IsA()); + TObject::Streamer(R__b); + R__b << findex; + R__b << flay; + R__b << flad; + R__b << fdet; + R__b << ftrksM; + R__b << fChi2; +// R__b.WriteArray(fx0, 3); +// R__b.WriteArray((double*)fM, 9); +// R__b.WriteArray(fangles, 3); + } +} diff --git a/ITS/AliITSAlignmentModule.h b/ITS/AliITSAlignmentModule.h new file mode 100644 index 00000000000..dc2701cde44 --- /dev/null +++ b/ITS/AliITSAlignmentModule.h @@ -0,0 +1,79 @@ +#ifndef ALIITSALIGNMENTMODULE_H +#define ALIITSALIGNMENTMODULE_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ +/* $Id$ */ +/* $Author$ */ +/* $Date$ */ +/* $Name$ */ +/* $Header$ */ +/* + $Log$ + Revision 1.1.2.2 2000/03/04 23:39:56 nilsen + Fixed the logs??? + + Revision 1.1.2.1 2000/03/02 20:12:57 nilsen + A new class useful for ITS detector Alignment studdies +*/ +/* $Revision$ */ + +// Standard C & C++ libraries +#include + +// Standard Root Libraries +#include "TParticle.h" + +// ITS libraries +#include "AliITSgeom.h" + +class AliITSAlignmentModule : public TObject{ +/////////////////////////////////////////////////////////////////////////// +// A track class define exclusively for the use in doing ITS detector +// alignment studdies. Not intended for general use. +// Author: B. S. Nilsen +// Date: January 17 2000 +/////////////////////////////////////////////////////////////////////////// + + protected: + + Int_t findex,flay,flad,fdet; + TObjArray *ftrksM; + Double_t fChi2; + Double_t fx0[3],fM[3][3],fangles[3]; + + public: + + AliITSAlignmentModule(); + AliITSAlignmentModule(Int_t index,AliITSgeom *gm, + Int_t ntrk,AliITSAlignmentTrack *trk); + virtual ~AliITSAlignmentModule() {;}; // default destructor OK + Int_t GetIndex(){return findex;} + void GetId(Int_t &lay,Int_t &lad,Int_t &det){lay=flay;lad=flad;det=fdet;} + Double_t * GetTranslationVector(){return fx0;} + Double_t * GetRotationAngles(){return fangles;} + Double_t ComputeChi2(); + Double_t GetChi2(){return fChi2;} + void AlignModule(); + void lnsrch(Int_t npar,Double_t *xold,Double_t fold,Double_t *g, + Double_t *p,Double_t *x,Double_t &f,Double_t stpmax, + Int_t &check); + void MRVMminimization(Int_t npar,Double_t *p,Double_t &fret,Double_t gtol, + Int_t &iter); + void SetByAngles(Double_t *th); + + private: + void dfMdthx(Double_t dfMx[3][3]); + void dfMdthy(Double_t dfMx[3][3]); + void dfMdthz(Double_t dfMx[3][3]); + void LtoG(Double_t xl[],Double_t xg[]); + void GtoL(Double_t xg[],Double_t xl[]); + Double_t Chi2(Double_t p[]); + void dChi2(Double_t p[],Double_t dChi2[]); + + + ClassDef(AliITSAlignmentModule,1) // Module class for ITS Alignment + + +}; +#endif diff --git a/ITS/AliITSAlignmentTrack.cxx b/ITS/AliITSAlignmentTrack.cxx new file mode 100644 index 00000000000..52549bc874d --- /dev/null +++ b/ITS/AliITSAlignmentTrack.cxx @@ -0,0 +1,400 @@ +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ +/* $Id$ */ +/* $Author$ */ +/* $Date$ */ +/* $Name$ */ +/* $Header$ */ +/* + $Log$ + Revision 1.1.2.2 2000/06/04 16:35:37 nilsen + One more try to fix log comments. + + Revision 1.1.2.1 2000/03/02 20:13:52 nilsen + A new class useful for ITS detector alignment studdies. + */ +/* $Revision$ */ + +// Standard Root Libraries +#include + +// ITS libraries +#include "AliITSgeom.h" +#include "AliITSAlignmentTrack.h" +#include "AliITSstatistics.h" +#include "AliITSstatistics2.h" + +ClassImp(AliITSAlignmentTrack) + +//______________________________________________________________________ +AliITSAlignmentTrack::AliITSAlignmentTrack(){ + + ftrack=fnclust=0,fnclustMax=0; + ffunc=-1; + fclust=0; + for(Int_t i=0;i<10;i++) fpar[i]=0.0; + fpx=fpy=fpz=fp=fpt=0.0; + fChi2=-1.0; +} +//______________________________________________________________________ +AliITSAlignmentTrack::~AliITSAlignmentTrack(){ + + ftrack=fnclust=0,fnclustMax=0; + ffunc=-1; + delete[] fclust; + fclust=0; + for(Int_t i=0;i<10;i++) fpar[i]=0.0; + fpx=fpy=fpz=fp=fpt=0.0; + fChi2=-1.0; +} +//______________________________________________________________________ +void AliITSAlignmentTrack::func0(Double_t *go,Double_t *gi){ + Double_t x,y,z; + + x = gi[0]; + y = gi[1]; + z = gi[2]; + x = fpar[0]+fpar[1]*z; + y = fpar[2]+fpar[3]*z; + go[0] = x; + go[1] = y; + go[2] = z; + return; +} +//______________________________________________________________________ +void AliITSAlignmentTrack::func1(Double_t *go,Double_t *gi){ + Double_t x,y,z; + + x = gi[0]; + y = gi[1]; + z = gi[2]; + x = fpar[0]+fpar[1]*y; + z = fpar[2]+fpar[3]*y; + go[0] = x; + go[1] = y; + go[2] = z; + return; +} +//______________________________________________________________________ +void AliITSAlignmentTrack::func2(Double_t *go,Double_t *gi){ + Double_t x,y,z,r,th; + + x = gi[0]; + y = gi[1]; + z = gi[2]; + th = TMath::ATan2(y-fpar[1],x-fpar[0]); + r = TMath::Hypot(x-fpar[0],y-fpar[1]); + if(th<0.0) th += 2.0*TMath::Pi(); + x = fpar[0]+fpar[2]*TMath::Cos(th); + y = fpar[1]+fpar[2]*TMath::Sin(th); + z = fpar[3]+fpar[4]*r; + go[0] = x; + go[1] = y; + go[2] = z; + return; +} +//______________________________________________________________________ +void AliITSAlignmentTrack::func(Double_t *go,Double_t *gi){ + + switch (ffunc){ + case 0: + func0(go,gi); + return; + case 1: + func1(go,gi); + return; + case 2: + func2(go,gi); + return; + } // end switch +} +//______________________________________________________________________ +Double_t AliITSAlignmentTrack::ComputeChi2(){ + Int_t i,j,k,l; + Double_t chi2=0.0,go[3],gi[3]; + + switch (ffunc) { + case -1: + return -1.0; + break; + case 0: + for(i=0;iReset(); + sy->Reset(); + x = fclust[i].fxg[0]; + y = fclust[i].fxg[1]; + z = fclust[i].fxg[2]; + wx = 1./(1./fclust[i].fExg[0][0] + + (1./fclust[i].fExg[2][2])*b0*b0);// 1.0/rms^2 + wy = 1./(1./fclust[i].fExg[1][1] + + (1./fclust[i].fExg[2][2])*d0*d0);// 1.0/rms^2 + sx->AddValue(x,z,wx); + sy->AddValue(y,z,wy); + } // end for i + fChi2 = sx->FitToLine(a,b); + fChi2 += sy->FitToLine(c,d); + //} while(fabs(b0-b)<1.E-5 && fabs(d0-d)<1.E-5); + } while(TMath::Abs(b0-b)<1.E-5 && TMath::Abs(d0-d)<1.E-5); + fpar[0] = a; + fpar[1] = b; + fpar[2] = c; + fpar[3] = d; + return 0; +} +//______________________________________________________________________ +Int_t AliITSAlignmentTrack::FitTrackToLineL(AliITSgeom *gm){ +// X = fpar[0] + fpar[1] * y; +// Z = fpar[2] + fpar[3] * y; +// in the local coordinate system of the detector fclust[0].findex. + // Local Variables + Int_t i,j,k; + Double_t wx/*,wy*/,wz,Exll[3][3]; + Double_t a,b,c,d; + Double_t xg[3],xl[3],x2g[3],x2l[3]; + AliITSstatistics2 *Fx = new AliITSstatistics2(2); + AliITSstatistics2 *Fz = new AliITSstatistics2(2); + + fChi2 = -1.0; + ffunc = 1; + if(fnclust<3) return -1; + + Int_t Npts = fnclust; + for(i=0;iLtoL(fclust[i].findex,fclust[0].findex,x2l,xl); + gm->LtoLErrorMatrix(fclust[i].findex,fclust[0].findex, + (Double_t **) fclust[i].fExl,(Double_t **) Exll); + wx = Exll[0][0]; + wz = Exll[2][2]; + Fx->AddValue(xl[0],xl[1],wx); + Fz->AddValue(xl[2],xl[1],wz); + } // end for i + fChi2 = Fx->FitToLine(a,b); + fChi2 += Fz->FitToLine(c,d); + fpar[0] = a; + fpar[1] = b; + fpar[2] = c; + fpar[3] = d; + // convert to global if posible. + xl[0] = a; + xl[1] = 0.0; + xl[2] = c; + x2l[0] = a+b; + x2l[1] = 1.0; + x2l[2] = c+d; + gm->LtoG(fclust[0].findex,xl,xg); + gm->LtoG(fclust[0].findex,x2l,x2g); + c = xg[2] - x2g[2]; + if(c!=0.0){ + b = (xg[0] - x2g[0])/c; + d = (xg[1] - x2g[1])/c; + a = xg[0] - b*xg[2]; + c = xg[1] - d*xg[2]; + fpar[4] = a; + fpar[5] = b; + fpar[6] = c; + fpar[7] = d; + }else{ + fpar[4] = 0.0; + fpar[5] = 0.0; + fpar[6] = 0.0; + fpar[7] = 0.0; + return -1; + }// end if c!=0.0 + return 0; +} +//______________________________________________________________________ +void AliITSAlignmentTrack::FitToFunction(Int_t n,AliITSgeom *gm){ + Int_t i,j,k,l; + Double_t r,w,xc[3],x1[3],x2[3],x3[3]; + AliITSstatistics2 *sa = new AliITSstatistics2(4); + AliITSstatistics2 *sb = new AliITSstatistics2(4); + + ffunc = -1; + if(fnclust<3) return; + + switch (n){ + case -1: + return; + break; + case 0: + ffunc = 0; + FitTrackToLineG(); + return; + break; + case 1: + ffunc = 1; + FitTrackToLineL(gm); + return; + break; + case 2: + ffunc = 2; + sa->Reset(); + sb->Reset(); + for(i=0;iAddValue((Double_t)fclust[i].fxg[2],r,w); + if(iAddValue(xc[1],xc[0],w); + } // end for j,k + } // end for i + fpar[0] = sa->GetMeanX(); + fpar[1] = sa->GetMeanY(); + fpar[2] = sb->GetMeanX(); + fChi2 = sb->FitToLine(fpar[3],fpar[4]); + fChi2 = (Float_t) ComputeChi2(); + return; + break; + default: + return; + break; + } // end switch + return; +} +//______________________________________________________________________ +void AliITSAlignmentTrack::Streamer(TBuffer &R__b){ + // Stream an object of class AliITSAlignmentTrack. + + if (R__b.IsReading()) { + Version_t R__v = R__b.ReadVersion(); if (R__v) { } + TObject::Streamer(R__b); + R__b >> ftrack; + R__b >> fnclust; + R__b >> fnclustMax; +// R__b >> fclust; + R__b >> ffunc; + R__b.ReadStaticArray(fpar); + R__b >> fChi2; + R__b >> fpx; + R__b >> fpy; + R__b >> fpz; + R__b >> fp; + R__b >> fpt; + } else { + R__b.WriteVersion(AliITSAlignmentTrack::IsA()); + TObject::Streamer(R__b); + R__b << ftrack; + R__b << fnclust; + R__b << fnclustMax; +// R__b << fclust; + R__b << ffunc; + R__b.WriteArray(fpar, 10); + R__b << fChi2; + R__b << fpx; + R__b << fpy; + R__b << fpz; + R__b << fp; + R__b << fpt; + } +} diff --git a/ITS/AliITSAlignmentTrack.h b/ITS/AliITSAlignmentTrack.h new file mode 100644 index 00000000000..a802bb72b12 --- /dev/null +++ b/ITS/AliITSAlignmentTrack.h @@ -0,0 +1,158 @@ +#ifndef ALIITSALIGNMENTTRACK_H +#define ALIITSALIGNMENTTRACK_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ +/* $Id$ */ +/* $Author$ */ +/* $Date$ */ +/* $Name$ */ +/* $Header$ */ +/* + $Log$ + Revision 1.1.2.4 2000/06/04 16:35:24 nilsen + One more try to fix log comments. + + Revision 1.1.2.3 2000/03/12 16:05:55 nilsen + Fixed but in $Log$ + Fixed but in Revision 1.1.2.4 2000/06/04 16:35:24 nilsen + Fixed but in One more try to fix log comments. + Fixed but in, hopefully. + + Revision 1.1.2.2 2000/03/04 23:40:19 nilsen + Fixed the logs??? + + Revision 1.1.2.1 2000/03/02 20:14:25 nilsen + A new class useful for ITS detector alignment studdies. +*/ +/* $Revision$ */ + +// Standard C & C++ libraries + +// Standard Root Libraries +#include +#include + +// ITS libraries +#include "AliITSgeom.h" + +struct TClustAl_sl{ + Int_t findex; + Float_t fxg[3],fExg[3][3]; + Float_t fxl[3],fExl[3][3]; +}; + + + +class AliITSAlignmentTrack : public TObject{ +/////////////////////////////////////////////////////////////////////////// +// A track class define exclusively for the use in doing ITS detector +// alignment studdies. Not intended for general use. +// Author: B. S. Nilsen +// Date: January 17 2000 +/////////////////////////////////////////////////////////////////////////// + + protected: + + Int_t ftrack,fnclust,fnclustMax; + TClustAl_sl *fclust; + Int_t ffunc; + Double_t fpar[10]; + Float_t fChi2; + Float_t fpx,fpy,fpz,fp,fpt; + // x=fp[0]+fp[1]*z and y=fp[2]+fp[3]*z : ffunc = 0 + // + // x=fp[0]+fp[1]*y and z=fp[2]+fp[3]*y : ffunc = 1 + // + // x=fp[0]+fp[2]*cos(th), y=fp[1]+fp[2]*sin(th), + // and z=fp[3]+f[4]*th th[i]=atan2(y[i]-y0,x[i]-x0) : ffunc = 2 + + public: + + AliITSAlignmentTrack(); + virtual ~AliITSAlignmentTrack(); + + void CreatePoints(Int_t n){fclust = new TClustAl_sl[n];fnclustMax=n; + fnclust=0;for(Int_t j=0;j=fnclustMax)return 0;fclust[n].findex=indx; + for(Int_t i=0;i<3;i++){fclust[n].fxl[i]=lp[i];for(Int_t j=0;j<3;j++) + fclust[n].fExl[i][j]=lep[i][j];}return -1;} + Int_t AddPointLastL(Int_t indx,Float_t *lp,Float_t **lep){ + if(++fnclust>=fnclustMax)return 0;//+first + fclust[fnclust].findex=indx; + for(Int_t i=0;i<3;i++){fclust[fnclust].fxl[i]=lp[i]; + for(Int_t j=0;j<3;j++)fclust[fnclust].fExl[i][j]=lep[i][j]; + }return -1;} + Int_t GetPointL(Int_t n,Float_t *lp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++) + lp[i]=fclust[n].fxl[i];return -1;} + Int_t GetPointL(Int_t n,Double_t *lp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++) + lp[i]=(Double_t)fclust[n].fxl[i];return -1;} + Int_t GetPointG(Int_t n,Float_t *gp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++) + gp[i]=fclust[n].fxg[i];return -1;} + Int_t GetPointG(Int_t n,Double_t *gp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++) + gp[i]=(Double_t)fclust[n].fxg[i];return -1;} + Int_t GetErrorG(Int_t n,Float_t **gp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) + gp[i][j]=fclust[n].fExg[i][j];return -1;} + Int_t GetErrorG(Int_t n,Double_t **gp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) + gp[i][j]=(Double_t)fclust[n].fExg[i][j];return -1;} + Int_t GetErrorL(Int_t n,Float_t **gp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) + gp[i][j]=fclust[n].fExl[i][j];return -1;} + Int_t GetErrorL(Int_t n,Double_t **gp){if(n>=fnclustMax)return 0; + for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) + gp[i][j]=(Double_t)fclust[n].fExl[i][j];return -1;} + Int_t GetIndex(Int_t n,Int_t &indx){if(n>=fnclustMax)return 0; + indx=fclust[n].findex;return -1;} + + void SetGlobalPosition(AliITSgeom *gm){ + for(Int_t i=0;iLtoG(fclust[i].findex,fclust[i].fxl,fclust[i].fxg); + gm->LtoGErrorMatrix(fclust[i].findex,(Double_t **) fclust[i].fExl, + (Double_t **) fclust[i].fExg);}} + void SetTrackNumber(Int_t trk) {ftrack=trk;} + void SetTParticle(TParticle *prt){fpx=prt->Px();fpy=prt->Py(); + fpz=prt->Pz();fp=prt->P();fpt=prt->Pt();} + void SetPx(Float_t px) {fpx=px;} + void SetPy(Float_t py) {fpy=py;} + void SetPz(Float_t pz) {fpz=pz;} + void SetP(Float_t p) {fp=p;} + void SetPt(Float_t pt) {fpt=pt;} + void SetParameter(Int_t n,Double_t a) {if(n>=0&&n<10);fpar[n]=a;} + void SetChi2(Float_t chi2) {fChi2=chi2;} + void SetFunctionNumber(Int_t fn) {ffunc = fn;} + + Int_t GetTrackNumber() {return ftrack;} + Int_t GetNumberOfClustersSl() {return fnclust;} + Float_t GetPx() {return fpx;} + Float_t GetPy() {return fpy;} + Float_t GetPz() {return fpz;} + Float_t GetP() {return fp;} + Float_t GetPt() {return fpt;} + Double_t GetParameter(Int_t n) {if(n>=0&&n<10) return fpar[n]; return -1.;} + Float_t GetChi2() {return fChi2;} + Int_t GetfunID() {return ffunc;} + + void FitToFunction(Int_t n,AliITSgeom *gm); + void func(Double_t *go,Double_t *gi); + void func0(Double_t *go,Double_t *gi); + void func1(Double_t *go,Double_t *gi); + void func2(Double_t *go,Double_t *gi); + Int_t FitTrackToLineG(); + Int_t FitTrackToLineL(AliITSgeom *gm); + Int_t FindCircleCenter(Double_t *xc,Double_t *x1, + Double_t *x2,Double_t *x3); + + private: + Double_t ComputeChi2(); + + ClassDef(AliITSAlignmentTrack,1) // Track class for ITS Alignment + +}; +#endif diff --git a/ITS/AliITSClusterFinder.cxx b/ITS/AliITSClusterFinder.cxx index c925bc44aba..74bac6d19f0 100644 --- a/ITS/AliITSClusterFinder.cxx +++ b/ITS/AliITSClusterFinder.cxx @@ -13,18 +13,9 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ - #include "AliITSClusterFinder.h" -#include "TTree.h" #include "AliRun.h" -#include -#include -#include -#include -#include -#include - -class AliITSRecPointNew; +#include "AliITS.h" //---------------------------------------------------------- diff --git a/ITS/AliITSClusterFinder.h b/ITS/AliITSClusterFinder.h index 509fcd82a5c..21b5df0b756 100644 --- a/ITS/AliITSClusterFinder.h +++ b/ITS/AliITSClusterFinder.h @@ -3,17 +3,22 @@ //////////////////////////////////////////////// -// ITS Cluster Finder Class // +// ITS Cluster Finder Class // //////////////////////////////////////////////// -#include "AliITSMap.h" +#include +#include + +class AliITSMap; +class AliITSresponse; +class AliITSsegmentation; +class AliITSRawCluster; +class AliITS; //--------------------------------------------------------------- class AliITSClusterFinder :public TObject { public: - TClonesArray *fDigits; // digits - Int_t fNdigits; // num of digits AliITSClusterFinder(AliITSsegmentation *seg, AliITSresponse *resp, TClonesArray *digits); AliITSClusterFinder(); @@ -97,6 +102,11 @@ public: } // set the fitting methods in the derived classes + + // data members + + TClonesArray *fDigits; // digits + Int_t fNdigits; // num of digits protected: AliITSresponse *fResponse; // response diff --git a/ITS/AliITSClusterFinderSDD.cxx b/ITS/AliITSClusterFinderSDD.cxx index 72dc8e16874..fb44bc7524b 100644 --- a/ITS/AliITSClusterFinderSDD.cxx +++ b/ITS/AliITSClusterFinderSDD.cxx @@ -15,6 +15,9 @@ #include "AliITSClusterFinderSDD.h" +#include "AliITSMapA2.h" +#include "AliITSMapA1.h" +#include "AliITS.h" #include "AliRun.h" @@ -31,13 +34,12 @@ AliITSClusterFinderSDD::AliITSClusterFinderSDD fDigits=digits; fClusters=recp; fNclusters= fClusters->GetEntriesFast(); - printf("SDD: fNclusters %d\n",fNclusters); SetCutAmplitude(); SetDAnode(); SetDTime(); - SetMap(); SetMinPeak(); SetNCells(); + SetMap(); } //_____________________________________________________________________________ @@ -49,15 +51,25 @@ AliITSClusterFinderSDD::AliITSClusterFinderSDD() fDigits=0; fClusters=0; fNclusters=0; + fMap=0; + fMapA2=0; SetCutAmplitude(); SetDAnode(); SetDTime(); - SetMap(); SetMinPeak(); SetNCells(); } +//_____________________________________________________________________________ +AliITSClusterFinderSDD::~AliITSClusterFinderSDD() +{ + // destructor + + if(fMap) delete fMap; + if(fMapA2) delete fMapA2; + +} //__________________________________________________________________________ AliITSClusterFinderSDD::AliITSClusterFinderSDD(const AliITSClusterFinderSDD &source){ // Copy Constructor @@ -65,6 +77,7 @@ AliITSClusterFinderSDD::AliITSClusterFinderSDD(const AliITSClusterFinderSDD &sou this->fClusters = source.fClusters ; this->fNclusters = source.fNclusters ; this->fMap = source.fMap ; + this->fMapA2 = source.fMapA2 ; this->fCutAmplitude = source.fCutAmplitude ; this->fDAnode = source.fDAnode ; this->fDTime = source.fDTime ; @@ -81,6 +94,7 @@ AliITSClusterFinderSDD& this->fClusters = source.fClusters ; this->fNclusters = source.fNclusters ; this->fMap = source.fMap ; + this->fMapA2 = source.fMapA2 ; this->fCutAmplitude = source.fCutAmplitude ; this->fDAnode = source.fDAnode ; this->fDTime = source.fDTime ; @@ -93,30 +107,8 @@ AliITSClusterFinderSDD& 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; ndigUncheckedAt(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); - } - + if(!fMapA2) fMapA2=new AliITSMapA2(fSegmentation,fDigits,(double)fCutAmplitude); + if(!fMap) fMap=new AliITSMapA1(fSegmentation,fDigits); } //_____________________________________________________________________________ @@ -128,7 +120,6 @@ void AliITSClusterFinderSDD::Find1DClusters() AliITS *iTS=(AliITS*)gAlice->GetModule("ITS"); // retrieve the parameters - Int_t i; Int_t fNofMaps = fSegmentation->Npz(); Int_t fMaxNofSamples = fSegmentation->Npx(); Int_t fNofAnodes = fNofMaps/2; @@ -139,7 +130,7 @@ void AliITSClusterFinderSDD::Find1DClusters() Float_t anodePitch = fSegmentation->Dpz(dummy); // map the signal - FillMap(); + fMapA2->FillMap(); // Piergiorgio's code - do not subtract baseline since we start // from digits and do not duplicate arrays, i.e. use fMap instead @@ -147,11 +138,9 @@ void AliITSClusterFinderSDD::Find1DClusters() Int_t nofFoundClusters = 0; - + Int_t i; Float_t **dfadc = new Float_t*[fNofMaps]; for(i=0;iGetSignal(idx,l); - fadc1=(Float_t)fMap->GetSignal(idx,l-1); + fadc2=(Float_t)fMapA2->GetSignal(idx,l); + fadc1=(Float_t)fMapA2->GetSignal(idx,l-1); if(l>0) dfadc[k][l-1] = fadc2-fadc1; } // samples } // anodes @@ -192,10 +181,10 @@ void AliITSClusterFinderSDD::Find1DClusters() for(m=0;m<10;m++) { Int_t id = it+m; if(id>=fMaxNofSamples) break; - fadc=fMap->GetSignal(idx,id); + fadc=fMapA2->GetSignal(idx,id); if(fadc > fadcmax) { fadcmax = fadc; - if(fadc > fCutAmplitude) { lthra++; lthrt++; } + if(fadc > 0) { lthra++; lthrt++; } imax = id; } if(dfadc[k][id] > dfadcmax) { @@ -205,19 +194,19 @@ void AliITSClusterFinderSDD::Find1DClusters() } it = imaxd; // skip if no signal over threshold - if(fMap->GetSignal(idx,imax) < fCutAmplitude) {it++; continue;} + if(fMapA2->TestHit(idx,imax) == kEmpty) {it++; continue;} if(k>0) { - if(fMap->GetSignal(idx-1,imax) > fCutAmplitude) lthra++; + if(fMapA2->TestHit(idx-1,imax) != kEmpty) lthra++; } if(kGetSignal(idx+1,imax) > fCutAmplitude) lthra++; + if(fMapA2->TestHit(idx+1,imax) != kEmpty) lthra++; if(imax>0) { - if(fMap->GetSignal(idx,imax-1) > fCutAmplitude) lthrt++; + if(fMapA2->TestHit(idx,imax-1) != kEmpty) lthrt++; } if(imaxGetSignal(idx,imax+1) > fCutAmplitude) lthrt++; + if(fMapA2->TestHit(idx,imax+1) != kEmpty) lthrt++; // cluster charge Int_t tstart = it-1; @@ -244,7 +233,7 @@ void AliITSClusterFinderSDD::Find1DClusters() Float_t clusterPeakAmplitude = 0.; Int_t its; for(its=tstart; its<=tstop; its++) { - fadc=fMap->GetSignal(idx,its); + fadc=fMapA2->GetSignal(idx,its); clusterCharge += fadc; if(fadc > clusterPeakAmplitude) clusterPeakAmplitude = fadc; clusterTime += fadc*its; @@ -283,12 +272,8 @@ void AliITSClusterFinderSDD::Find1DClusters() } // anodes } // detectors (2) - Int_t nofClusters = fClusters->GetEntriesFast(); - nofClusters -= fNclusters; - - //printf("SDD- Find1Dclust: fNclusters nofClusters %d %d \n",fNclusters, nofClusters); - fMap->ClearMap(); + fMapA2->ClearMap(); for(i=0;iGetEntriesFast(); nofClusters -= fNclusters; - //printf("SDD- GroupClusters: fNclusters nofClusters %d %d \n",fNclusters, nofClusters); - AliITSRawClusterSDD *clusterI; AliITSRawClusterSDD *clusterJ; @@ -328,8 +311,8 @@ void AliITSClusterFinderSDD::GroupClusters() if(clusterI->T() < fTimeStep*10) fDAnode = 1.2; Bool_t pair = clusterI->Brother(clusterJ,fDAnode,fDTime); if(!pair) continue; - // clusterI->Print(); - // clusterJ->Print(); + // clusterI->PrintInfo(); + // clusterJ->PrintInfo(); clusterI->Add(clusterJ); label[j] = 1; fClusters->RemoveAt(j); @@ -351,8 +334,6 @@ void AliITSClusterFinderSDD::SelectClusters() Int_t nofClusters = fClusters->GetEntriesFast(); nofClusters -= fNclusters; - //printf("SDD- SelectClusters: fNclusters nofClusters %d %d \n",fNclusters, nofClusters); - Int_t i; for(i=0; iAt(i); @@ -376,7 +357,6 @@ void AliITSClusterFinderSDD::SelectClusters() void AliITSClusterFinderSDD::GetRecPoints() { // get rec points - //static Int_t counter=0; AliITS *iTS=(AliITS*)gAlice->GetModule("ITS"); @@ -384,31 +364,32 @@ void AliITSClusterFinderSDD::GetRecPoints() 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; + fMap->FillMap(); + + Int_t i, ix, iz; for(i=0; iAt(i); + fSegmentation->GetPadIxz(clusterI->X(),clusterI->Z(),ix,iz); + AliITSdigitSDD *dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix-1); 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.); + rnew.fTracks[0]=dig->fTracks[0]; + rnew.fTracks[1]=dig->fTracks[1]; + rnew.fTracks[2]=dig->fTracks[2]; iTS->AddRecPoint(rnew); - //counter++; } // I clusters - //printf("counter %d\n",counter); + fMap->ClearMap(); } //_____________________________________________________________________________ diff --git a/ITS/AliITSClusterFinderSDD.h b/ITS/AliITSClusterFinderSDD.h index f2c5a480a21..e4172da6786 100644 --- a/ITS/AliITSClusterFinderSDD.h +++ b/ITS/AliITSClusterFinderSDD.h @@ -7,6 +7,8 @@ #include "AliITSClusterFinder.h" +class AliITSMapA2; + class AliITSClusterFinderSDD : public AliITSClusterFinder @@ -16,14 +18,12 @@ public: (AliITSsegmentation *seg, AliITSresponse *response, TClonesArray *digits,TClonesArray *recpoints); AliITSClusterFinderSDD(); - virtual ~AliITSClusterFinderSDD(){ - // destructor - } + virtual ~AliITSClusterFinderSDD(); AliITSClusterFinderSDD(const AliITSClusterFinderSDD &source); // copy constructor AliITSClusterFinderSDD& operator=(const AliITSClusterFinderSDD &source); // assignment operator virtual void SetMap(); - virtual void SetCutAmplitude(Float_t thres=1.2) { + virtual void SetCutAmplitude(Float_t thres=0.0) { // set cut amplitude fCutAmplitude=thres; } @@ -39,13 +39,11 @@ public: // SetMinPeak fMinPeak=minpeak; } - virtual void SetNCells(Int_t minc=4) { + virtual void SetNCells(Int_t minc=5) { // setNCells fMinNCells=minc; } - void FillMap(); - // Search for clusters virtual void FindRawClusters(); void Find1DClusters(); @@ -57,7 +55,7 @@ private: TClonesArray *fClusters; // clusters Int_t fNclusters; // num of clusters - AliITSMapA2 *fMap; // map + AliITSMapA2 *fMapA2; // signal map Float_t fCutAmplitude; // cut amplitude Float_t fDAnode; // fDanode Float_t fDTime; // fDtime @@ -65,7 +63,6 @@ private: 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 index 026bf0a6a35..815c372abd9 100644 --- a/ITS/AliITSClusterFinderSPD.cxx +++ b/ITS/AliITSClusterFinderSPD.cxx @@ -15,6 +15,8 @@ #include "AliITSClusterFinderSPD.h" +#include "AliITSMapA1.h" +#include "AliITS.h" #include "AliRun.h" @@ -44,13 +46,21 @@ AliITSClusterFinderSPD::AliITSClusterFinderSPD() fDigits=0; fClusters=0; fNclusters=0; + fMap=0; SetDx(); SetDz(); - SetMap(); SetNCells(); } +//_____________________________________________________________________________ +AliITSClusterFinderSPD::~AliITSClusterFinderSPD() +{ + // destructor + if (fMap) delete fMap; + + +} //__________________________________________________________________________ AliITSClusterFinderSPD::AliITSClusterFinderSPD(const AliITSClusterFinderSPD &source){ // Copy Constructor @@ -122,13 +132,13 @@ void AliITSClusterFinderSPD::Find1DClusters() id = it+m; if(id >= fMaxNofSamples) break; // ! no possible for the fadc - if(fMap->GetHitIndex(k,id)) { // start of the cluster + if(fMap->TestHit(k,id) == kUnused) { // start of the cluster lclx += 1; if(lclx == 1) xstart = id; } - if(lclx > 0 && !fMap->GetHitIndex(k,id)) { + if(lclx > 0 && fMap->TestHit(k,id) == kEmpty) { // end of cluster if a gap exists xstop = id-1; ilcl = 1; @@ -143,14 +153,14 @@ void AliITSClusterFinderSPD::Find1DClusters() if(id >= fMaxNofSamples && lclx == 0) break; // the x row finished if(id < fMaxNofSamples && ilcl == 0 && lclx > 0) { - // cluster end is outside of the window, + // cluster end is outside of the window, mmax += 5; // increase mmax and repeat the cluster - // finding + // finding it -= 1; } if(id >= fMaxNofSamples && lclx > 0) { // the x row finished but - xstop = fMaxNofSamples - 1; // the end cluster exists + xstop = fMaxNofSamples - 1; // the end cluster exists ilcl = 1; } @@ -161,11 +171,10 @@ void AliITSClusterFinderSPD::Find1DClusters() 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); + fSegmentation->GetPadCxz(dummy,k,dummyX,clusterZ); Float_t zstart = clusterZ - 0.5*zpitch; Float_t zstop = clusterZ + 0.5*zpitch; Float_t clusterX = 0.; @@ -177,7 +186,7 @@ void AliITSClusterFinderSPD::Find1DClusters() Int_t its; for(its=xstart; its<=xstop; its++) { Int_t firedpixel=0; - if (fMap->GetHitIndex(k,its)) firedpixel=1; + if (fMap->GetHitIndex(k,its)>=0) firedpixel=1; clusterCharge += firedpixel; clusterX +=its + 0.5; } @@ -204,6 +213,8 @@ void AliITSClusterFinderSPD::Find1DClusters() } // new cluster (ilcl=1) } // X direction loop (it) } // Z direction loop (k) + + //fMap->ClearMap(); return; } @@ -217,12 +228,11 @@ void AliITSClusterFinderSPD::GroupClusters() // 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=new Int_t[nofClusters]; Int_t i,j; for(i=0; iXStop() == clusterJ->XStart()-1)||(clusterI->XStart()==clusterJ->XStop()+1)) cout<<"!! Diagonal cluster"<Print(); - clusterJ->Print(); + clusterI->PrintInfo(); + clusterJ->PrintInfo(); */ clusterI->Add(clusterJ); // cout << "remove cluster " << j << endl; @@ -246,7 +256,7 @@ void AliITSClusterFinderSPD::GroupClusters() fClusters->RemoveAt(j); /* cout << "cluster " << i << " after grouping" << endl; - clusterI->Print(); + clusterI->PrintInfo(); */ } // pair } // J clusters @@ -257,7 +267,7 @@ void AliITSClusterFinderSPD::GroupClusters() //cout << " Nomber of clusters at the group end ="<< totalNofClusters<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; + Float_t spdLength = fSegmentation->Dz(); + Float_t spdWidth = fSegmentation->Dx(); + + Int_t i, ix, iz; for(i=0; iAt(i); + fSegmentation->GetPadIxz(clusterI->X(),clusterI->Z(),ix,iz); + AliITSdigitSPD *dig = (AliITSdigitSPD*)fMap->GetHit(iz-1,ix-1); AliITSRecPoint rnew; - rnew.SetX(clusterI->X()*kconv); - rnew.SetZ(clusterI->Z()*kconv); + rnew.SetX((clusterI->X() - spdWidth/2)*kconv); + rnew.SetZ((clusterI->Z() - spdLength/2)*kconv); rnew.SetQ(1.); rnew.SetdEdX(0.); rnew.SetSigmaX2(kRMSx*kRMSx); rnew.SetSigmaZ2(kRMSz*kRMSz); - rnew.SetProbability(1.); + rnew.fTracks[0]=dig->fTracks[0]; + rnew.fTracks[1]=dig->fTracks[1]; + rnew.fTracks[2]=dig->fTracks[2]; iTS->AddRecPoint(rnew); } // I clusters + + fMap->ClearMap(); } //_____________________________________________________________________________ @@ -301,5 +320,6 @@ void AliITSClusterFinderSPD::FindRawClusters() Find1DClusters(); GroupClusters(); GetRecPoints(); + } diff --git a/ITS/AliITSClusterFinderSPD.h b/ITS/AliITSClusterFinderSPD.h index 89d2ce35871..23a34591fb0 100644 --- a/ITS/AliITSClusterFinderSPD.h +++ b/ITS/AliITSClusterFinderSPD.h @@ -7,6 +7,8 @@ #include "AliITSClusterFinder.h" +class AliITSMapA1; + class AliITSClusterFinderSPD : public AliITSClusterFinder @@ -16,9 +18,7 @@ public: (AliITSsegmentation *segmentation, TClonesArray *digits, TClonesArray *recpoints); AliITSClusterFinderSPD(); - virtual ~AliITSClusterFinderSPD(){ - // destructor - } + virtual ~AliITSClusterFinderSPD(); AliITSClusterFinderSPD(const AliITSClusterFinderSPD &source); // copy constructor AliITSClusterFinderSPD& operator=(const AliITSClusterFinderSPD &source); // assignment operator @@ -49,14 +49,13 @@ 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 + Int_t fMinNCells; // min num of cells in the cluster ClassDef(AliITSClusterFinderSPD,1) // SPD clustering - Boris B. algo based - // on Piergiorgio's algo + // on Piergiorgio's algo }; #endif diff --git a/ITS/AliITSClusterFinderSSD.cxx b/ITS/AliITSClusterFinderSSD.cxx index c3b894e6b5d..cf436464607 100644 --- a/ITS/AliITSClusterFinderSSD.cxx +++ b/ITS/AliITSClusterFinderSSD.cxx @@ -28,7 +28,11 @@ Automatic combination routines improved (traps) */ #include "AliRun.h" +#include "AliITS.h" +#include "AliITSMapA1.h" #include "AliITSClusterFinderSSD.h" +#include "AliITSclusterSSD.h" +#include "AliITSpackageSSD.h" const Int_t debug=0; @@ -49,6 +53,8 @@ AliITSClusterFinderSSD::AliITSClusterFinderSSD(AliITSsegmentation *seg, TClonesA fDigits=digits; fRecPoints=recp; + fMap = new AliITSMapA1(fSegmentation,fDigits); + fITS=(AliITS*)gAlice->GetModule("ITS"); fClusterP = new TClonesArray ("AliITSclusterSSD",200); @@ -77,7 +83,9 @@ AliITSClusterFinderSSD::AliITSClusterFinderSSD(AliITSsegmentation *seg, TClonesA fSegmentation->Angles(StereoP,StereoN); fTanP=TMath::Tan(StereoP); fTanN=TMath::Tan(StereoN); + fPNsignalRatio=7./8.; // warning: hard-wired number + } //------------------------------------------------------- @@ -88,6 +96,9 @@ AliITSClusterFinderSSD::~AliITSClusterFinderSSD() { delete fPackages; delete fDigitsIndexP; delete fDigitsIndexN; + + delete fMap; + } //------------------------------------------------------- @@ -96,18 +107,18 @@ void AliITSClusterFinderSSD::InitReconstruction() register Int_t i; //iterator - for(i=0;iRemoveAt(i); } fNClusterP =0; - for(i=0;iRemoveAt(i); } fNClusterN=0; - for(i=0;iRemoveAt(i); } @@ -128,9 +139,6 @@ void AliITSClusterFinderSSD::InitReconstruction() //--------------------------------------------- void AliITSClusterFinderSSD::FindRawClusters() { - - - //Piotr Krzysztof Skowronski //Warsaw University of Technology //skowron@if.pw.edu.pl @@ -144,6 +152,7 @@ void AliITSClusterFinderSSD::FindRawClusters() // 5. Creates clusters InitReconstruction(); //ad. 1 + fMap->FillMap(); FillDigitsIndex(); SortDigits(); FindNeighbouringDigits(); //ad. 2 @@ -152,7 +161,8 @@ void AliITSClusterFinderSSD::FindRawClusters() ConsumeClusters(); PackagesToPoints(); //ad. 5 ReconstructNotConsumedClusters(); - + + fMap->ClearMap(); } @@ -185,7 +195,7 @@ void AliITSClusterFinderSSD::FindNeighbouringDigits() dnumber = 1; dbuffer[0]=lDigitsIndexP[0]; //If next digit is a neighbour of previous, adds to last cluster this digit - for(i=1; i GetStripNumber(); @@ -194,12 +204,12 @@ void AliITSClusterFinderSSD::FindNeighbouringDigits() == (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexP[i]; else { //create a new one side cluster - new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEP); + new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,fgkSIDEP); dbuffer[0]=lDigitsIndexP[i]; dnumber = 1; } } // end loop over fNDigitsP - new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEP); + new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,fgkSIDEP); //process N side @@ -207,18 +217,18 @@ void AliITSClusterFinderSSD::FindNeighbouringDigits() dnumber = 1; dbuffer[0]=lDigitsIndexN[0]; //If next digit is a neighbour of previous, adds to last cluster this digit - for(i=1; i GetStripNumber(); if ( (((AliITSdigitSSD*)lDigits[lDigitsIndexN[i-1]])->GetStripNumber()) == (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexN[i]; else { - new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEN); + new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,fgkSIDEN); dbuffer[0]=lDigitsIndexN[i]; dnumber = 1; } } // end loop over fNDigitsN - new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,SIDEN); + new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,fDigits,fgkSIDEN); delete [] dbuffer; } // end condition on NDigits @@ -236,7 +246,7 @@ void AliITSClusterFinderSSD::SeparateOverlappedClusters() //Warsaw University of Technology //skowron@if.pw.edu.pl - register Int_t i,j; //iterator + register Int_t i; //iterator Float_t factor=0.75; // How many percent must be lower signal // on the middle one digit @@ -253,12 +263,12 @@ void AliITSClusterFinderSSD::SeparateOverlappedClusters() splitlist = new TArrayI(300); - for(i=0;iGetNumOfDigits())==1) continue; if (( ((AliITSclusterSSD*)(*fClusterP)[i])->GetNumOfDigits())==2) continue; Int_t nj=(((AliITSclusterSSD*)(*fClusterP)[i])->GetNumOfDigits()-1); - for(j=1; jGetDigitSignal(j); signal0=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j-1); @@ -270,17 +280,17 @@ void AliITSClusterFinderSSD::SeparateOverlappedClusters() } } // end loop over number of digits //split this cluster if necessary - if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,SIDEP); + if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,fgkSIDEP); numerofsplits=0; //in signed places (splitlist) } // end loop over clusters on Pside - for(i=0;iGetNumOfDigits())==1) continue; if (( ((AliITSclusterSSD*)(*fClusterN)[i])->GetNumOfDigits())==2) continue; Int_t nj=(((AliITSclusterSSD*)(*fClusterN)[i])->GetNumOfDigits()-1); - for(j=1; jGetDigitSignal(j); signal0=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j-1); @@ -290,7 +300,7 @@ void AliITSClusterFinderSSD::SeparateOverlappedClusters() (*splitlist)[numerofsplits++]=j; } // end loop over number of digits //split this cluster into more clusters - if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,SIDEN); + if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,fgkSIDEN); numerofsplits=0; //in signed places (splitlist) } // end loop over clusters on Nside @@ -325,7 +335,7 @@ void AliITSClusterFinderSSD::SplitCluster(TArrayI *list, Int_t nsplits, Int_t in // side true means P side if (side) { curentcluster =((AliITSclusterSSD*)((*fClusterP)[index])) ; - for(i = nsplits; i>0 ;i--) { + for (i = nsplits; i>0 ;i--) { NN=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits); new ((*fClusterP)[fNClusterP]) AliITSclusterSSD(NN,tmpdigits,fDigits,side); ( (AliITSclusterSSD*)((*fClusterP)[fNClusterP]) )-> @@ -340,7 +350,7 @@ void AliITSClusterFinderSSD::SplitCluster(TArrayI *list, Int_t nsplits, Int_t in } // end loop over nplits } else { curentcluster =((AliITSclusterSSD*)((*fClusterN)[index])); - for(i = nsplits; i>0 ;i--) { + for (i = nsplits; i>0 ;i--) { NN=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits); new ((*fClusterN)[fNClusterN]) AliITSclusterSSD(NN,tmpdigits,fDigits,side); ((AliITSclusterSSD*)((*fClusterN)[fNClusterN]))-> @@ -449,14 +459,14 @@ void AliITSClusterFinderSSD::FillDigitsIndex() AliITSdigitSSD *dig; - for(i = 0 ; i< N; i++ ) { + 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;kGetStripNumber(); // same as above - for(k=0;k1) - for(i=0;i1) - for(i=0;i1) - for(i=0;i1) - for(i=0;iAddPSideCluster(oneSclP[i]); //Check, if next N side clusters crosses with it too tmplastNclIndex=lastNclIndex; - for(k=1;kGetNumOfClustersN(); @@ -881,7 +892,7 @@ void AliITSClusterFinderSSD:: ResolveClusterWithOneCross(AliITSpackageSSD *currentpkg, Int_t clusterIndex, Bool_t clSide) { - if (clSide == SIDEP) ResolvePClusterWithOneCross(currentpkg,clusterIndex); + if (clSide == fgkSIDEP) ResolvePClusterWithOneCross(currentpkg,clusterIndex); else ResolveNClusterWithOneCross(currentpkg,clusterIndex); } @@ -944,7 +955,7 @@ ie: ns = clusterN->GetTotalSignal(); posClusterN = GetClusterZ(clusterN); posErrorClusterN = clusterN->GetPositionError(); - pkg->DelCluster(clusterIndex,SIDEP); + pkg->DelCluster(clusterIndex,fgkSIDEP); sigClusterN = ps/fPNsignalRatio; // there is no sonse to check how signal ratio is far from perfect // matching line if the if below it is true @@ -952,7 +963,7 @@ ie: sigClusterN=ns; if (debug) cout<<"n1 < p1/fPNsignalRatio"; if (debug) cout<<"Attempting to del cluster N "<DelClusterOI(clusterIdx,SIDEN); + pkg->DelClusterOI(clusterIdx,fgkSIDEN); } else { //Let's see how signal ratio is far from perfect matching line Chicomb = DistToPML(ps,ns); @@ -960,7 +971,7 @@ ie: if (Chicomb > falpha2) { //it is near, so we can risk throwing this cluster away too if (debug) cout<<"Attempting to del cluster N "<DelClusterOI(clusterIdx,SIDEN); + pkg->DelClusterOI(clusterIdx,fgkSIDEN); } else { clusterN->CutTotalSignal(sigClusterN); if (debug) cout <<"Signal cut |||||||||||||\n"; @@ -1013,7 +1024,7 @@ ResolveNClusterWithOneCross(AliITSpackageSSD *pkg, Int_t clusterIndex) ps = clusterP->GetTotalSignal(); posClusterP = GetClusterZ(clusterP); posErrorClusterP = clusterP->GetPositionError(); - pkg->DelCluster(clusterIndex,SIDEN); + pkg->DelCluster(clusterIndex,fgkSIDEN); sigClusterP=ns*fPNsignalRatio; // there is no sonse to check how signal ratio is far from perfect // matching line if the if below it is true @@ -1021,7 +1032,7 @@ ResolveNClusterWithOneCross(AliITSpackageSSD *pkg, Int_t clusterIndex) sigClusterP = ps; if (debug) cout<<"ps < ns*fPNsignalRatio"; if (debug) cout<<"Attempting to del cluster P "<DelClusterOI(clusterIdx,SIDEP); + pkg->DelClusterOI(clusterIdx,fgkSIDEP); } else { //Let's see how signal ratio is far from perfect matching line Chicomb = DistToPML(ps,ns); @@ -1029,7 +1040,7 @@ ResolveNClusterWithOneCross(AliITSpackageSSD *pkg, Int_t clusterIndex) if (Chicomb > falpha2) { //it is near, so we can risk frowing this cluster away too if (debug) cout<<"Attempting to del cluster P "<DelClusterOI(clusterIdx,SIDEP); + pkg->DelClusterOI(clusterIdx,fgkSIDEP); } else { clusterN->CutTotalSignal(sigClusterP); if (debug) cout <<"Signal cut ------------\n"; @@ -1060,9 +1071,9 @@ ResolvePackageBestCombin(AliITSpackageSSD *pkg) 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 ++) { + for (itera =2; itera <= NP ;itera ++) { sizet=sizet*itera; if (sizet > 10000) { sizet=10000; @@ -1070,9 +1081,9 @@ ResolvePackageBestCombin(AliITSpackageSSD *pkg) } } - Int_t **combin = new Int_t*[sizet]; //2D array to keep combinations in + Int_t** combin = new Int_t*[sizet]; //2D array to keep combinations in - for(itera =0; itera GetPSideCluster(itera); //carefully here //becase AliITSclusterSSD::GetCross returns index in @@ -1095,7 +1106,7 @@ ResolvePackageBestCombin(AliITSpackageSSD *pkg) CreateNewRecPoint(clusterP, clusterN, 0.75); } - for(itera =0; itera DelClusterOI(pi, SIDEP); - pkg->DelClusterOI(ni, SIDEN); + pkg->DelClusterOI(pi, fgkSIDEP); + pkg->DelClusterOI(ni, fgkSIDEN); if (split) { if (debug) cout<<"spltting package ...\n"; @@ -1222,12 +1233,12 @@ void AliITSClusterFinderSSD:: ResolvePackageWithOnePSideCluster(AliITSpackageSSD XPerr = clusterP->GetPositionError(); p1err = clusterP->GetTotalSignalError(); - for(k=0;kGetNSideCluster(k)->GetTotalSignal(); SNerr[k] = pkg->GetNSideCluster(k)->GetTotalSignalError(); sumsig += SN[k]; } - for(k=0;kGetNSideCluster(k); SP[k]= p1*SN[k]/sumsig; SPerr[k] = p1err*SN[k]/sumsig; @@ -1287,13 +1298,13 @@ void AliITSClusterFinderSSD::ResolvePackageWithOneNSideCluster(AliITSpackageSSD n1err=clusterN->GetTotalSignalError(); - for(k=0;kGetPSideCluster(k)->GetTotalSignal(); sumsig += SP[k]; SPerr[k] = pkg->GetPSideCluster(k)->GetTotalSignalError(); } - for(k=0;kGetPSideCluster(k); SN[k]= n1*SP[k]/sumsig; XP[k]=GetClusterZ(clusterP); @@ -1497,6 +1508,9 @@ CreateNewRecPoint(Float_t P, Float_t dP, Float_t N, Float_t dN, Float_t p=P; Float_t n=N; + Int_t stripP, stripN; + Int_t sigP, sigN; + AliITSdigitSSD *digP, *digN; if (GetCrossing(P,N)) { GetCrossingError(dP,dN); AliITSRawClusterSSD cnew; @@ -1509,8 +1523,7 @@ CreateNewRecPoint(Float_t P, Float_t dP, Float_t N, Float_t dN, printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsP); nstripsP=100; } - Int_t i; - for(i=0;iGetDigitStripNo(i)' returns the digit index cnew.fIndexMap[i] = clusterP->GetDigitStripNo(i); } @@ -1518,7 +1531,7 @@ CreateNewRecPoint(Float_t P, Float_t dP, Float_t N, Float_t dN, printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsN); nstripsN=100; } - for(i=0;iGetDigitStripNo(i)' returns the digit index cnew.fIndexMapN[i] = clusterN->GetDigitStripNo(i); } @@ -1526,6 +1539,11 @@ CreateNewRecPoint(Float_t P, Float_t dP, Float_t N, Float_t dN, cnew.fQErr=dSig; //cnew.fProbability=(float)prob; fITS->AddCluster(2,&cnew); + fSegmentation->GetPadIxz(P,N,stripP,stripN); + digP = (AliITSdigitSSD*)fMap->GetHit(1,stripP); + digN = (AliITSdigitSSD*)fMap->GetHit(0,stripN); + sigP = digP->fSignal; + sigN = digN->fSignal; // add the rec point info AliITSRecPoint rnew; rnew.SetX(P*kconv); @@ -1535,6 +1553,15 @@ CreateNewRecPoint(Float_t P, Float_t dP, Float_t N, Float_t dN, rnew.SetSigmaX2( kRMSx* kRMSx); rnew.SetSigmaZ2( kRMSz* kRMSz); rnew.SetProbability((float)prob); + if(sigP > sigN) { + rnew.fTracks[0]=digP->fTracks[0]; + rnew.fTracks[1]=digP->fTracks[1]; + rnew.fTracks[2]=digP->fTracks[2]; + } else { + rnew.fTracks[0]=digN->fTracks[0]; + rnew.fTracks[1]=digN->fTracks[1]; + rnew.fTracks[2]=digN->fTracks[2]; + } fITS->AddRecPoint(rnew); /* // it was @@ -1616,8 +1643,8 @@ Bool_t AliITSClusterFinderSSD::Strip2Local( Float_t stripP, Float_t stripN, Floa X=P; Z=N; if (debug) cout<<"P="<-2.1)&&(X<3.65)&&(X>-3.65)) return true; - else return false; + if ((Z<2.1)&&(Z>-2.1)&&(X<3.65)&&(X>-3.65)) return kTRUE; + else return kFALSE; } @@ -1660,12 +1687,11 @@ Int_t AliITSClusterFinderSSD::GetBestComb Float_t chi; Float_t ps, ns; //signal of P cluster and N cluster - Int_t i,j; - for(i=0;iGetPSideCluster(j)->GetTotalSignal(); //carrefully here, different functions ns = GetNSideCluster(comb[i][j])->GetTotalSignal(); @@ -1708,8 +1734,7 @@ void AliITSClusterFinderSSD::GetBestMatchingPoint bestchi=DistToPML( pkg->GetPSideCluster(0)->GetTotalSignal(), pkg->GetNSideCluster(0)->GetTotalSignal() ); - Int_t i,j; - for(i = 0; i< pkg->GetNumOfClustersP(); i++) + for (Int_t i = 0; i< pkg->GetNumOfClustersP(); i++) { p = pkg->GetPSideClusterIdx(i); @@ -1717,7 +1742,7 @@ void AliITSClusterFinderSSD::GetBestMatchingPoint nc=curPcl->GetCrossNo(); ps=curPcl->GetTotalSignal(); - for(j = 0; j< nc; j++) + for (Int_t j = 0; j< nc; j++) { n=curPcl->GetCross(j); curNcl= GetNSideCluster(n); @@ -1820,8 +1845,8 @@ AliITSclusterSSD* AliITSClusterFinderSSD::GetCluster(Int_t idx, Bool_t side) void AliITSClusterFinderSSD::ConsumeClusters() { - Int_t i; - for(i=0;iConsumeClusters(); } @@ -1847,9 +1872,10 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() 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;iIsConsumed()) { @@ -1875,8 +1901,7 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsP); nstripsP=100; } - Int_t k; - for(k=0;kGetDigitStripNo(i)' returns // the digit index and not smth else cnew.fIndexMap[k] = cluster->GetDigitStripNo(k); @@ -1885,6 +1910,8 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() cnew.fQErr=sigerr; //cnew.fProbability=0.75; fITS->AddCluster(2,&cnew); + fSegmentation->GetPadIxz((x1+x2)/2,(z1+z2)/2,stripP,stripN); + dig = (AliITSdigitSSD*)fMap->GetHit(1,stripP); // add the rec point info AliITSRecPoint rnew; rnew.SetX(kconv*(x1+x2)/2); @@ -1894,6 +1921,9 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() rnew.SetSigmaX2( kRMSx* kRMSx); rnew.SetSigmaZ2( kRMSz* kRMSz); rnew.SetProbability(0.75); + rnew.fTracks[0]=dig->fTracks[0]; + rnew.fTracks[1]=dig->fTracks[1]; + rnew.fTracks[2]=dig->fTracks[2]; fITS->AddRecPoint(rnew); /* fPointsM->AddLast( (TObject*) @@ -1906,9 +1936,8 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() } } - for(i=0;iIsConsumed()) { @@ -1936,8 +1965,7 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() printf("multiplicity > 100 - increase the dimension of the arrays %d\n",nstripsN); nstripsN=100; } - Int_t k; - for(k=0;kGetDigitStripNo(i)' returns // the digit index and not smth else cnew.fIndexMapN[k] = cluster->GetDigitStripNo(k); @@ -1947,6 +1975,8 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() //cnew.fProbability=0.75; fITS->AddCluster(2,&cnew); // add the rec point info + fSegmentation->GetPadIxz((x1+x2)/2,(z1+z2)/2,stripP,stripN); + dig = (AliITSdigitSSD*)fMap->GetHit(0,stripN); AliITSRecPoint rnew; rnew.SetX(kconv*(x1+x2)/2); rnew.SetZ(kconv*(z1+z2)/2); @@ -1955,6 +1985,9 @@ void AliITSClusterFinderSSD::ReconstructNotConsumedClusters() rnew.SetSigmaX2( kRMSx* kRMSx); rnew.SetSigmaZ2( kRMSz* kRMSz); rnew.SetProbability(0.75); + rnew.fTracks[0]=dig->fTracks[0]; + rnew.fTracks[1]=dig->fTracks[1]; + rnew.fTracks[2]=dig->fTracks[2]; fITS->AddRecPoint(rnew); /* fPointsM->AddLast( (TObject*) diff --git a/ITS/AliITSClusterFinderSSD.h b/ITS/AliITSClusterFinderSSD.h index 8b85cff8304..f8c0d0af934 100644 --- a/ITS/AliITSClusterFinderSSD.h +++ b/ITS/AliITSClusterFinderSSD.h @@ -4,17 +4,15 @@ * See cxx source for full Copyright notice */ -#include #include -#include #include #include -#include "AliITS.h" -#include "AliITSclusterSSD.h" -#include "AliITSpackageSSD.h" #include "AliITSClusterFinder.h" +class AliITSclusterSSD; +class AliITSpackageSSD; + class AliITSClusterFinderSSD: public AliITSClusterFinder { @@ -139,9 +137,10 @@ public: Float_t falpha2; Float_t falpha3; Float_t fPNsignalRatio; + - static const Bool_t SIDEP=kTRUE; - static const Bool_t SIDEN=kFALSE; + static const Bool_t fgkSIDEP=kTRUE; + static const Bool_t fgkSIDEN=kFALSE; Int_t fSFF; //forward stepping factor Int_t fSFB; //backward stepping factor diff --git a/ITS/AliITSDetType.h b/ITS/AliITSDetType.h index 37993650bd0..18ba69e7df2 100644 --- a/ITS/AliITSDetType.h +++ b/ITS/AliITSDetType.h @@ -8,6 +8,7 @@ #include "AliITSsegmentation.h" #include "AliITSresponse.h" + class AliITSClusterFinder; class AliITSsimulation; @@ -47,7 +48,7 @@ class AliITSDetType:public TObject // Configure reconstruction model fReconst = thisReconstruction; } - void ClassNames(char * digit, char * cluster) { + void ClassNames(const char *digit, const char *cluster) { // Set class names for digits and clusters fDigClassName=digit; fClustClassName=cluster; } @@ -70,10 +71,10 @@ class AliITSDetType:public TObject } // - void GetClassNames(char* &digit, char* &cluster) + void GetClassNames(char *digit,char *cluster) { // Get class names for digits and rec points - digit=fDigClassName; cluster=fClustClassName; + strcpy(digit,fDigClassName.Data()); strcpy(cluster,fClustClassName.Data()); } protected: @@ -83,13 +84,11 @@ protected: AliITSresponse *fResponse; // response AliITSsegmentation *fSegmentation; // segmentation - char* fDigClassName; //! - // string - char* fClustClassName; //! - // string + TString fDigClassName; // string + TString fClustClassName; // string ClassDef(AliITSDetType,1) - }; +}; #endif diff --git a/ITS/AliITSHuffman.cxx b/ITS/AliITSHuffman.cxx index 2c3cdaac64e..72fc4a0d090 100644 --- a/ITS/AliITSHuffman.cxx +++ b/ITS/AliITSHuffman.cxx @@ -27,7 +27,7 @@ AliITSHNode::AliITSHNode() AliITSHNode::AliITSHNode(UChar_t sym, ULong_t freq) { - // constructor + // standard constructor fSymbol=sym; fFrequency=freq; fLeft=0; @@ -104,10 +104,10 @@ AliITSHTable::AliITSHTable(Int_t size) fHNodes = new TObjArray; fNnodes=0; fSym= new Short_t[fSize]; - for(Short_t i=0;i 0) { fNnodes++; @@ -197,7 +195,7 @@ void AliITSHTable::BuildHTable() } - Clear(); + ClearTable(); AliITSHNode *start= (AliITSHNode*)fHNodes->UncheckedAt(0); SpanTree(start,0,0); @@ -205,8 +203,7 @@ void AliITSHTable::BuildHTable() // check the Huffman table cout << "...Done, Huffman Table is: \n"; - Int_t c; - for(c=0; c <= 255; c++) { + for (int c=0; c <= 255; c++) { if (fCodeLen[c] > 0) cout << "Symbol " << c << " Coded as " << fCode[c] << " and long " << (int) fCodeLen[c] << " bits.\n"; } @@ -263,36 +260,10 @@ void AliITSHTable::ResetHNodes() } //_____________________________________________________________________________ -void AliITSHTable::Clear() +void AliITSHTable::ClearTable() { // 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 index d3649ef6b3b..bbd0e35a9ec 100644 --- a/ITS/AliITSHuffman.h +++ b/ITS/AliITSHuffman.h @@ -17,14 +17,6 @@ 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); @@ -41,7 +33,15 @@ class AliITSHNode: public TObject { Int_t Compare(TObject *obj); ClassDef(AliITSHNode,1) //HuffT node object for set:ITS - }; + + 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 +}; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Attention! Next class has kept deliberaty in @@ -79,15 +79,15 @@ public: void BuildHTable(); Bool_t SpanTree(AliITSHNode*start, ULong_t code, UChar_t len); void ResetHNodes(); - void Clear(); + void ClearTable(); protected: Int_t fSize; // size of the arrays - UChar_t *fCodeLen; //[fSize] number of bits array - ULong_t *fCode; //[fSize] coded symbols array + UChar_t *fCodeLen; //![fSize] number of bits array + ULong_t *fCode; //![fSize] coded symbols array - Short_t *fSym; //[fSize] array of input symbols + Short_t *fSym; //![fSize] array of input symbols TObjArray *fHNodes; // array of nodes Int_t fNnodes; // number of nodes diff --git a/ITS/AliITSMap.cxx b/ITS/AliITSMap.cxx index ce23b6e7b95..0ed43cb9bbf 100644 --- a/ITS/AliITSMap.cxx +++ b/ITS/AliITSMap.cxx @@ -13,421 +13,9 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -#include + #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; ndigUncheckedAt(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; ndigUncheckedAt(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 (indexUncheckedAt(i); - Int_t nsamples = hist->GetNbinsX(); - for(j=0; jGetBinContent(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; iUncheckedAt(i); - for(j=0; j= fMapThreshold) hist->Fill((Float_t)j,signal); - } - } - -} -//-------------------------------------- -void AliITSMapA2::ResetHist() -{ - // - // Reset histograms - // - - if (!fObjects) return; - - Int_t i; - for(i=0; iReset(); - } - -} -//______________________________________________________________________________ -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 index 97ddeee3d50..b6e8d4c0ef9 100644 --- a/ITS/AliITSMap.h +++ b/ITS/AliITSMap.h @@ -2,9 +2,9 @@ #define ALIITSMAP_H -#include "AliITS.h" +#include -typedef enum {kEmpty, kUsed, kUnused} Flag_t; +typedef enum {kEmpty, kUsed, kUnused} FlagType; //___________________________________________________________________________ @@ -13,104 +13,28 @@ class AliITSMap : public: virtual ~AliITSMap() {} + // Fill hits from list of digits into hit map virtual void FillMap() =0; + // Clear the map virtual void ClearMap() =0; + // Set a single hit virtual void SetHit(Int_t iz, Int_t ix, Int_t idigit) =0; + // Delete a single hit virtual void DeleteHit(Int_t iz, Int_t ix) =0; - virtual void FlagHit(Int_t iz, Int_t ix) =0; + // Flag a hit as used + virtual void FlagHit(Int_t iz, Int_t ix) =0; + // Get index of hit in the list of digits virtual Int_t GetHitIndex(Int_t iz, Int_t ix) =0; + // Get pointer to digit virtual TObject * GetHit(Int_t iz, Int_t ix) =0; - virtual Flag_t TestHit(Int_t iz, Int_t ix) =0; + // Test hit status + virtual FlagType TestHit(Int_t iz, Int_t ix) =0; + // Get signal from map 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/AliITSMapA1.cxx b/ITS/AliITSMapA1.cxx new file mode 100644 index 00000000000..5639fef3d1f --- /dev/null +++ b/ITS/AliITSMapA1.cxx @@ -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. * + **************************************************************************/ + + +#include "AliITSMapA1.h" +#include "AliITSsegmentation.h" +#include "AliITSresponse.h" +#include "AliITSdigit.h" + +#include +#include + + +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(); + if (!ndigits) return; + + AliITSdigit *dig; + for (Int_t ndig=0; ndigUncheckedAt(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 + if (fHitMap[CheckedIndex(iz, ix)]) return TMath::Abs(fHitMap[CheckedIndex(iz, ix)])-1; + else return 0; +} + +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)); +} + +Double_t AliITSMapA1::GetSignal(Int_t iz, Int_t ix) +{ + // get a pad signal + AliITSdigit *dig = (AliITSdigit*)GetHit(iz,ix); + return (Double_t)dig->fSignal; + +} + +FlagType 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; + } +} diff --git a/ITS/AliITSMapA1.h b/ITS/AliITSMapA1.h new file mode 100644 index 00000000000..75e5eff6d94 --- /dev/null +++ b/ITS/AliITSMapA1.h @@ -0,0 +1,66 @@ +#ifndef ALIITSMAPA1_H +#define ALIITSMAPA1_H + + +#include "AliITSMap.h" +class AliITSsegmentation; +class TObjArray; + + +class AliITSMapA1 : + public AliITSMap +{ + +public: + AliITSMapA1() { + // constructor + } + AliITSMapA1(AliITSsegmentation *seg); + AliITSMapA1(AliITSsegmentation *seg, TObjArray *dig); + AliITSMapA1(const AliITSMapA1 &source); + // Assignment operator + AliITSMapA1& operator=(const AliITSMapA1 &source); + + virtual ~AliITSMapA1(); + // Fill hits from list of digits into hit map + virtual void FillMap(); + // Clear the hit map + virtual void ClearMap(); + // Set a single hit + virtual void SetHit(Int_t iz, Int_t ix, Int_t idigit); + // Delete a single hit + virtual void DeleteHit(Int_t iz, Int_t ix); + // Get index of hit in the list of digits + virtual Int_t GetHitIndex(Int_t iz, Int_t ix); + // Get pointer to digit + virtual TObject* GetHit(Int_t iz, Int_t ix); + // Flag a hit as used + virtual void FlagHit(Int_t iz, Int_t ix); + // Test hit status + virtual FlagType TestHit(Int_t iz, Int_t ix); + // Get signal from map + virtual Double_t GetSignal(Int_t iz, Int_t ix); + // Get max index inmap + Int_t MaxIndex() {return fMaxIndex;} + // Set the array of objects + void SetArray(TObjArray *obj); + +protected: + // Check index + Int_t CheckedIndex(Int_t iz, Int_t ix); + + AliITSsegmentation *fSegmentation; // segmentation class + Int_t fNpx; // fNpx + Int_t fNpz; // fNpz + TObjArray *fObjects; // object + Int_t fNobjects; // number of objects + Int_t fMaxIndex; // max index in map + +private: + Int_t *fHitMap; //! [fMaxIndex] + + ClassDef(AliITSMapA1,1) // Implements Hit/Digit Map +}; + +#endif + diff --git a/ITS/AliITSMapA2.cxx b/ITS/AliITSMapA2.cxx new file mode 100644 index 00000000000..27b611502f6 --- /dev/null +++ b/ITS/AliITSMapA2.cxx @@ -0,0 +1,258 @@ +/************************************************************************** + * 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 +#include +#include + +#include "AliITSMapA2.h" +#include "AliITSsegmentation.h" +#include "AliITSresponse.h" +#include "AliITSdigit.h" + + +ClassImp(AliITSMapA2) + + AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg) +{ + //constructor + fScaleSizeZ=1; + fScaleSizeX=1; + 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, Int_t scalesizeX, Int_t scalesizeZ) +{ + //constructor + fSegmentation = seg; + fScaleSizeX=scalesizeX; + fScaleSizeZ=scalesizeZ; + fNpz=fScaleSizeZ*fSegmentation->Npz(); + fNpx=fScaleSizeX*fSegmentation->Npx(); + fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector + + fHitMap = new Double_t[fMaxIndex]; + fMapThreshold=0.; + ClearMap(); +} + +//-------------------------------------- +AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg, TObjArray *obj, Double_t thresh) +{ + //constructor + fScaleSizeZ=1; + fScaleSizeX=1; + fSegmentation = seg; + fNpz=fSegmentation->Npz(); + fNpx=fSegmentation->Npx(); + fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector + + fHitMap = new Double_t[fMaxIndex]; + fObjects = obj; + 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->fScaleSizeX = source.fScaleSizeX; + this->fScaleSizeZ = source.fScaleSizeZ; + this->fHitMap = source.fHitMap; + return; +} + +//_________________________________________________________________________ +AliITSMapA2& + AliITSMapA2::operator=(const AliITSMapA2 &source) { + // Assignment operator + if(&source == this) return *this; + this->fMapThreshold = source.fMapThreshold; + this->fScaleSizeX = source.fScaleSizeX; + this->fScaleSizeZ = source.fScaleSizeZ; + 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(); + if (!ndigits) return; + + AliITSdigit *dig; + for (Int_t ndig=0; ndigUncheckedAt(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 (indexUncheckedAt(i); + Int_t nsamples = hist->GetNbinsX(); + for( Int_t j=0; jGetBinContent(j+1)); + if (signal >= fMapThreshold) SetHit(i,j,signal); + } + } + +} +//-------------------------------------- +void AliITSMapA2::FillHist() +{ + + // fill 1D histograms from map + if (!fObjects || fScaleSizeX != 1) return; + + // an example + for( Int_t i=0; iUncheckedAt(i); + for( Int_t j=0; j= fMapThreshold) hist->Fill((Float_t)j,signal); + } + } + +} +//-------------------------------------- +void AliITSMapA2::ResetHist() +{ + // + // Reset histograms + // + + if (!fObjects) return; + + for( Int_t i=0; iReset(); + } + +} + diff --git a/ITS/AliITSMapA2.h b/ITS/AliITSMapA2.h new file mode 100644 index 00000000000..45dd8d0d918 --- /dev/null +++ b/ITS/AliITSMapA2.h @@ -0,0 +1,55 @@ +#ifndef ALIITSMAPA2_H +#define ALIITSMAPA2_H + + +#include "AliITSMapA1.h" + +class AliITSMapA2 : +public AliITSMapA1 +{ + +public: + AliITSMapA2(AliITSsegmentation *seg); + AliITSMapA2(AliITSsegmentation *seg,Int_t scalesizeX,Int_t scalesizeZ); + AliITSMapA2(AliITSsegmentation *seg, TObjArray *hist,Double_t thresh); + virtual ~AliITSMapA2(); + AliITSMapA2(const AliITSMapA2 &source); // copy constructor + // assignment operator + AliITSMapA2& operator=(const AliITSMapA2 &source); + // fill pad signals into map + virtual void FillMap(); + // clear map + virtual void ClearMap(); + // set hit + virtual void SetHit(Int_t iz, Int_t ix, Int_t signal){} + // Flag a hit as used + virtual void FlagHit(Int_t iz, Int_t ix); + virtual void DeleteHit(Int_t iz, Int_t ix); + // Get index in the map + virtual Int_t GetHitIndex(Int_t iz, Int_t ix); + // Get object (1D histogram) + virtual TObject *GetHit(Int_t iz, Int_t dummy); + // Test hit status + virtual FlagType TestHit(Int_t iz, Int_t ix); + // Get signal + virtual Double_t GetSignal(Int_t iz, Int_t ix); + // set hit + void SetHit(Int_t iz, Int_t ix, Double_t signal); + // Get signal + Double_t GetSignal(Int_t index); + +private: + void FillMapFromHist(); + void FillHist(); + void ResetHist(); + + Double_t *fHitMap; //! [fMaxIndex] + Double_t fMapThreshold; // threshold for signal + Int_t fScaleSizeX; // scale factor on x + Int_t fScaleSizeZ; // scale factor on z + + ClassDef(AliITSMapA2,1) // Implements Signal Map +}; + + +#endif diff --git a/ITS/AliITSRawCluster.cxx b/ITS/AliITSRawCluster.cxx index 668518a5f58..150834b06f9 100644 --- a/ITS/AliITSRawCluster.cxx +++ b/ITS/AliITSRawCluster.cxx @@ -17,8 +17,7 @@ AliITSRawClusterSDD::AliITSRawClusterSDD(Int_t wing, Float_t Anode,Float_t Time, fNanodes = 1; fNsamples = Samples; Int_t sign = 1; - Int_t i; - for(i=0;i +#include "AliITSdigit.h" #include "AliITSclusterSSD.h" ClassImp(AliITSclusterSSD) @@ -7,7 +8,7 @@ ClassImp(AliITSclusterSSD) AliITSclusterSSD::AliITSclusterSSD() { // default constructor - fSide = true; + fSide = kTRUE; fDigits = 0; fNDigits = 0; fDigitsIndex = 0; @@ -63,11 +64,11 @@ AliITSclusterSSD::AliITSclusterSSD(const AliITSclusterSSD &OneSCluster) fNCrosses = OneSCluster.fNCrosses; fConsumed = OneSCluster.fConsumed; Int_t i; - for(i = 0; i< fNCrosses ; i++) + for (i = 0; i< fNCrosses ; i++) { fCrossedClusterIndexes[i] = OneSCluster.fCrossedClusterIndexes[i]; } - for(i = 0; i< fNDigits ; i++) + for (i = 0; i< fNDigits ; i++) { fDigitsIndex[i]=OneSCluster.fDigitsIndex[i]; } @@ -90,11 +91,11 @@ AliITSclusterSSD& AliITSclusterSSD::operator=(const AliITSclusterSSD & OneSClust fNCrosses = OneSCluster.fNCrosses; fConsumed = OneSCluster.fConsumed; Int_t i; - for(i = 0; i< fNCrosses ; i++) + for (i = 0; i< fNCrosses ; i++) { fCrossedClusterIndexes[i] = OneSCluster.fCrossedClusterIndexes[i]; } - for(i = 0; i< fNDigits ; i++) + for (i = 0; i< fNDigits ; i++) { fDigitsIndex[i]=OneSCluster.fDigitsIndex[i]; } @@ -115,8 +116,7 @@ Int_t AliITSclusterSSD::SplitCluster(Int_t where, Int_t *outdigits) 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++) + for (Int_t i = (where+1); i < tmp; i++) { outdigits[ind++]=(*fDigitsIndex)[i]; //"moving" strips from this to the new one (*fDigitsIndex)[i]=-1; @@ -172,8 +172,8 @@ Double_t AliITSclusterSSD::CentrOfGravity() 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;iGetTracks(); - for(i = 0; i<3;i++) + for (i = 0; i<3;i++) { fTrack[i]=tidx[i]; if (fTrack[i] != 0) fNTrack++; } - for(i = 1; iGetTracks(); - Int_t j; - for(j = 0; j<3;j++) + for (Int_t j = 0; j<3;j++) { bit = 1; if (tidx[j]==0) break; - Int_t k; - for(k = 0; k < fNTrack;k++) + for (Int_t k = 0; k < fNTrack;k++) { if (tidx[j]==fTrack[k]) bit =0; } @@ -380,8 +377,7 @@ Double_t AliITSclusterSSD::GetPositionError() Bool_t AliITSclusterSSD::IsCrossingWith(Int_t idx) { // comment to be written - Int_t i; - for(i =0; i< fNCrosses;i++) + for (Int_t i =0; i< fNCrosses;i++) { if (GetCross(i) == idx) return kTRUE; } diff --git a/ITS/AliITSclusterSSD.h b/ITS/AliITSclusterSSD.h index 8ac723d33a0..0ab04280e0b 100644 --- a/ITS/AliITSclusterSSD.h +++ b/ITS/AliITSclusterSSD.h @@ -3,9 +3,9 @@ #include "TObject.h" #include "TArrayI.h" -#include "AliITSdigit.h" #include "TClonesArray.h" +class AliITSdigitSSD; class AliITSclusterSSD : public TObject { diff --git a/ITS/AliITSdcsSSD.cxx b/ITS/AliITSdcsSSD.cxx index 7b4828231ad..4e594730fab 100644 --- a/ITS/AliITSdcsSSD.cxx +++ b/ITS/AliITSdcsSSD.cxx @@ -29,7 +29,7 @@ AliITSdcsSSD::AliITSdcsSSD(AliITSsegmentation *seg, AliITSresponse *resp) npar=6; } - Float_t *detpar = new Float_t [npar]; + Float_t *detpar= new Float_t[npar]; resp->GetDetParam(detpar); fNInvalid = detpar[0]; @@ -41,12 +41,11 @@ AliITSdcsSSD::AliITSdcsSSD(AliITSsegmentation *seg, AliITSresponse *resp) fCouplingNL = detpar[5]; - Option_t *opt,*dummy; + char opt[30],dummy[20]; resp->ParamOptions(opt,dummy); if (strstr(opt,"SetInvalid")) SetInvalidMC(fNInvalid,fISigma); - - delete [] detpar; + delete [] detpar; } //_____________________________________________________________________ @@ -169,8 +168,8 @@ void AliITSdcsSSD::GetInvalidParam(Float_t &mean, Float_t &sigma) { Bool_t AliITSdcsSSD::IsValidP(Int_t strip) { // isvalidP Int_t nElem = fInvalidP->GetSize(); - Int_t i; - for(i = 0; iAt(i) == strip) return kFALSE; return kTRUE; } @@ -180,8 +179,8 @@ Bool_t AliITSdcsSSD::IsValidP(Int_t strip) { Bool_t AliITSdcsSSD::IsValidN(Int_t strip) { // is valid N Int_t nElem = fInvalidN->GetSize(); - Int_t i; - for(i = 0; iAt(i) == strip) return kFALSE; return kTRUE; } diff --git a/ITS/AliITSdcsSSD.h b/ITS/AliITSdcsSSD.h index 17bd003bc7b..cf352968864 100644 --- a/ITS/AliITSdcsSSD.h +++ b/ITS/AliITSdcsSSD.h @@ -4,10 +4,6 @@ /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * See cxx source for full Copyright notice */ -#include -#include -#include - //____________________________________________________________________ // // Class AliITSdcsSSD @@ -26,6 +22,9 @@ //___________________________________________________________________ // +#include +#include +#include class AliITSsegmentation; class AliITSresponse; diff --git a/ITS/AliITSdictSSD.cxx b/ITS/AliITSdictSSD.cxx index 5377d07e634..df55a7ab1d1 100644 --- a/ITS/AliITSdictSSD.cxx +++ b/ITS/AliITSdictSSD.cxx @@ -1,22 +1,15 @@ #include -#include -#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; + Int_t exist = 0; - for(i=0; i<10; i++) + for(Int_t i=0; i<10; i++) { if(track == fTrack[i]) { diff --git a/ITS/AliITSdictSSD.h b/ITS/AliITSdictSSD.h index 12865cdea52..b18e55b0411 100644 --- a/ITS/AliITSdictSSD.h +++ b/ITS/AliITSdictSSD.h @@ -3,10 +3,6 @@ #include -#include "AliITSdcsSSD.h" - -class AliITSdcsSSD; - class AliITSdictSSD { public: diff --git a/ITS/AliITSdigit.cxx b/ITS/AliITSdigit.cxx index af7c69b2e35..e68d28928d6 100644 --- a/ITS/AliITSdigit.cxx +++ b/ITS/AliITSdigit.cxx @@ -33,7 +33,7 @@ ClassImp(AliITSdigitSPD) } //_____________________________________________________________________________ -AliITSdigitSPD::AliITSdigitSPD(Int_t *digits,Int_t *tracks) { +AliITSdigitSPD::AliITSdigitSPD(Int_t *digits,Int_t *tracks,Int_t *hits) { // // Creates a simulated SPD digit object // @@ -42,16 +42,16 @@ AliITSdigitSPD::AliITSdigitSPD(Int_t *digits,Int_t *tracks) { fCoord2 = digits[1]; fSignal = digits[2]; - Int_t i; - for(i=0; i<3; i++) { + for(Int_t i=0; i<3; i++) { fTracks[i] = tracks[i]; + fHits[i] = hits[i]; } } ClassImp(AliITSdigitSDD) //________________________________________________________________________ - AliITSdigitSDD::AliITSdigitSDD(Float_t phys,Int_t *digits) { +AliITSdigitSDD::AliITSdigitSDD(Float_t phys,Int_t *digits) { // // Creates a simulated SDD digit object to be updated // @@ -62,7 +62,7 @@ ClassImp(AliITSdigitSDD) } //_____________________________________________________________________________ -AliITSdigitSDD::AliITSdigitSDD(Float_t phys,Int_t *digits,Int_t *tracks, Float_t *charges) { +AliITSdigitSDD::AliITSdigitSDD(Float_t phys,Int_t *digits,Int_t *tracks,Int_t *hits,Float_t *charges) { // // Creates a simulated SDD digit object // @@ -71,17 +71,17 @@ AliITSdigitSDD::AliITSdigitSDD(Float_t phys,Int_t *digits,Int_t *tracks, Float_t fSignal = digits[2]; fPhysics = phys; - Int_t i; - for(i=0; i<3; i++) { + for(Int_t i=0; i<3; i++) { fTcharges[i] = charges[i]; fTracks[i] = tracks[i]; + fHits[i] = hits[i]; } } ClassImp(AliITSTransientDigit) //_______________________________________________________________________ - AliITSTransientDigit::AliITSTransientDigit(Float_t phys,Int_t *digits): +AliITSTransientDigit::AliITSTransientDigit(Float_t phys,Int_t *digits): AliITSdigitSDD(phys,digits) { // // Creates a digit object in a list of digits to be updated @@ -108,7 +108,7 @@ AliITSTransientDigit& ClassImp(AliITSdigitSSD) //__________________________________________________________________________ - AliITSdigitSSD::AliITSdigitSSD(Int_t *digits) { +AliITSdigitSSD::AliITSdigitSSD(Int_t *digits) { // // Creates a real SSD digit object // @@ -120,7 +120,7 @@ ClassImp(AliITSdigitSSD) } //_____________________________________________________________________________ -AliITSdigitSSD::AliITSdigitSSD(Int_t *digits,Int_t *tracks) { +AliITSdigitSSD::AliITSdigitSSD(Int_t *digits,Int_t *tracks,Int_t *hits) { // // Creates a simulated SSD digit object // @@ -128,10 +128,10 @@ AliITSdigitSSD::AliITSdigitSSD(Int_t *digits,Int_t *tracks) { fCoord1 = digits[0]; fCoord2 = digits[1]; fSignal = digits[2]; - - Int_t i; - for(i=0; i<3; i++) { + + for(Int_t i=0; i<3; i++) { fTracks[i] = tracks[i]; + fHits[i] = hits[i]; } } diff --git a/ITS/AliITSdigit.h b/ITS/AliITSdigit.h index 02d3884e5ce..d51fd4b5ee7 100644 --- a/ITS/AliITSdigit.h +++ b/ITS/AliITSdigit.h @@ -15,7 +15,7 @@ public: Int_t fCoord1; // Cell number on Z axis (SPD+SDD) , flag for side type (SSD) Int_t fCoord2 ; // Cell number on X axis (SPD+SDD) , strip number (SSD) - Int_t fSignal; // Signal + Int_t fSignal; // Signal in ADC counts public: AliITSdigit() { @@ -23,7 +23,7 @@ public: fSignal=fCoord1=fCoord2=0; } AliITSdigit(Int_t *digits); - virtual ~AliITSdigit() { + virtual ~AliITSdigit() { // destructor } @@ -37,18 +37,21 @@ public: // debugging -- goes to the dictionary Int_t fTracks[3]; // tracks making this digit + Int_t fHits[3]; // hits associated to the tracks + // 3 hits temporarily - it will be only 1 public: AliITSdigitSPD() { // constructor fSignal=fCoord1=fCoord2=0; - fTracks[0]=fTracks[1]=fTracks[2]=0; + fTracks[0]=fTracks[1]=fTracks[2]=-3; + fHits[0]=fHits[1]=fHits[2]=-1; } AliITSdigitSPD(Int_t *digits); - AliITSdigitSPD(Int_t *digits, Int_t *tracks); + AliITSdigitSPD(Int_t *digits, Int_t *tracks, Int_t *hits); - virtual ~AliITSdigitSPD(){ + virtual ~AliITSdigitSPD(){ // destructor } virtual int *GetTracks() { @@ -66,6 +69,8 @@ public: // debugging -- goes to the dictionary Int_t fTracks[3]; // tracks making this digit + Int_t fHits[3]; // hits associated to the tracks + // 3 hits temporarily - it will be only 1 Float_t fTcharges[3]; // charge per track making this digit Float_t fPhysics; // signal particles contribution to signal @@ -73,14 +78,15 @@ public: AliITSdigitSDD() { // constructor fSignal=fCoord1=fCoord2=0; - fTracks[0]=fTracks[1]=fTracks[2]=0; + fTracks[0]=fTracks[1]=fTracks[2]=-3; + fHits[0]=fHits[1]=fHits[2]=-1; fPhysics=0; fTcharges[0]=fTcharges[1]=fTcharges[2]=0; } AliITSdigitSDD(Float_t phys,Int_t *digits); - AliITSdigitSDD( Float_t phys, Int_t *digits, Int_t *tracks, Float_t *charges); + AliITSdigitSDD( Float_t phys, Int_t *digits, Int_t *tracks, Int_t *hits, Float_t *charges); - virtual ~AliITSdigitSDD(){ + virtual ~AliITSdigitSDD(){ // destructor } virtual int *GetTracks() { @@ -123,18 +129,21 @@ public: // debugging -- goes to the dictionary Int_t fTracks[3]; // tracks making this digit + Int_t fHits[3]; // hits associated to the tracks + // 3 hits temporarily - it will be only 1 public: AliITSdigitSSD() { // constructor fSignal=fCoord1=fCoord2=0; - fTracks[0]=fTracks[1]=fTracks[2]=0; + fTracks[0]=fTracks[1]=fTracks[2]=-3; + fHits[0]=fHits[1]=fHits[2]=-1; } AliITSdigitSSD(Int_t *digits); - AliITSdigitSSD(Int_t *digits, Int_t *tracks); + AliITSdigitSSD(Int_t *digits, Int_t *tracks, Int_t *hits); - virtual ~AliITSdigitSSD(){ + virtual ~AliITSdigitSSD(){ // destructor } diff --git a/ITS/AliITSdisplay.cxx b/ITS/AliITSdisplay.cxx new file mode 100644 index 00000000000..a640d9747e1 --- /dev/null +++ b/ITS/AliITSdisplay.cxx @@ -0,0 +1,1791 @@ +/************************************************************************** + * 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.10 1999/11/10 07:37:04 fca +Pads do not inherit editability from canvas any more + +Revision 1.9 1999/11/09 07:38:51 fca +Changes for compatibility with version 2.23 of ROOT + +Revision 1.8 1999/09/29 09:24:23 fca +Introduction of the Copyright and cvs Log + +*/ + + +////////////////////////////////////////////////////////////////////////// +// // +// AliDisplay // +// // +// Utility class to display ALICE outline, tracks, hits,.. // +// // +////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "AliRun.h" +#include "AliDetector.h" +#include "AliITS.h" +#include "AliITSdigitNew.h" +#include "AliITSMap.h" +#include "AliITSresponseV0.h" +#include "AliITSdisplay.h" +#include "AliITSpoints.h" +#include "TParticle.h" + + +const Int_t kMAXHIST = 20; + +static Int_t sModule=0; + + +ClassImp(AliITSdisplay) + + +//_____________________________________________________________________________ +AliITSdisplay::AliITSdisplay() +{ + fPoints = 0; + fPhits = 0; + fRpoints = 0; + fR2points = 0; + fCpoints = 0; + fCanvas = 0; + + fMap = 0; + +} + +//_____________________________________________________________________________ +AliITSdisplay::AliITSdisplay(Int_t size) +{ +// Create an event display object. +// A canvas named "edisplay" is created with a vertical size in pixels +// +// A QUICK Overview of the Event Display functions +// =============================================== +// +// The event display can ve invoked by executing the macro "display.C" +// A canvas like in the picture below will appear. +// +// On the left side of the canvas, the following buttons appear: +// *Next* to move to the next event +// *Previous* to move to the previous event + +// *Pick* Select this option to be able to point on a track with the +// mouse. Once on the track, use the right button to select +// an action. For example, select SetMarkerAttributes to +// change the marker type/color/size for the track. +// *Zoom* Select this option (default) if you want to zoom. +// To zoom, simply select the selected area with the left button. +// *UnZoom* To revert to the previous picture size. +// +// slider R On the left side, the vertical slider can be used to +// set the default picture size. +// +// When you are in Zoom mode, you can click on the black part of the canvas +// to select special options with the right mouse button. + +// +// When you are in pick mode, you can "Inspect" the object pointed by the mouse. +// When you are on a track, select the menu item "InspectParticle" +// to display the current particle attributes. +// +// You can activate the Root browser by selecting the Inspect menu +// in the canvas tool bar menu. Then select "Start Browser" +// This will open a new canvas with the browser. At this point, you may want +// to display some histograms (from the Trees). Go to the "File" menu +// of the browser and click on "New canvas". +// In the browser, click on item "ROOT files" in the left pane. +// Click on galice.root. +// Click on TH +// Click on TPC for example +// Click on any variable (eg TPC.fX) to histogram the variable. +// +// If you are lost, you can click on HELP in any Root canvas or browser. +//Begin_Html +/* + +*/ +//End_Html + + + fPad = 0; + + gAlice->SetDisplay(this); + + // Set module view by default + fTheta = -90; + fPhi = 90; + fPsi = 180; + + fYmodule = 0; + + fModule = 393; + fNmodules = 0; + + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + AliITSgeom *gm=ITS->GetITSgeom(); + gm->GetModuleId(fModule,fLayer,fLadder,fDetector); + + // fRzone = 1.e10; + fDrawClusters = kTRUE; + fDrawCoG = kTRUE; + fDrawCathCor = kFALSE; + fDrawHist = kFALSE; + + fMap = 0; + + + fZoomMode = 1; + fZooms = 0; + fClustersCuts = 0; + fPoints = 0; + fPhits = 0; + fRpoints = 0; + fR2points = 0; + fCpoints = 0; + + /* + // Initialize display default parameters + SetRange(3.5,3.5); + // Create colors + CreateColors(); + // Create display canvas + Int_t ysize = size; + if (ysize < 100) ysize = 750; + Int_t xsize = Int_t(size*830./ysize); + fCanvas = new TCanvas("ModuleCanvas", "ITS Clusters Display",14,47,xsize,ysize); + fCanvas->ToggleEventStatus(); + + // Create main display pad + fPad = new TPad("mviewpad", "ITS display",0.15,0,0.9,1); + fPad->Draw(); + fPad->Modified(); + fPad->SetFillColor(1); + fPad->SetBorderSize(2); + + fCanvas->cd(); + + // Create colors pad + fColPad = new TPad("colpad", "Colors pad",0.9,0,1,1); + fColPad->Draw(); + fColPad->Modified(); + fColPad->SetFillColor(19); + fColPad->SetBorderSize(2); + fColPad->cd(); + DisplayColorScale(); + + fCanvas->cd(); + + // Create user interface control pad + DisplayButtons(); + fCanvas->cd(); + + // Create Range and mode pad + Float_t dxtr = 0.15; + Float_t dytr = 0.45; + fTrigPad = new TPad("mtrigger", "range and mode pad",0,0,dxtr,dytr); + fTrigPad->SetEditable(kFALSE); + fTrigPad->Draw(); + fTrigPad->cd(); + fTrigPad->SetFillColor(22); + fTrigPad->SetBorderSize(2); + fRangeSlider = new TSlider("mrange","range",0.7,0.42,0.9,0.98); + fRangeSlider->SetObject(this); + //char pickmode[] = "gAlice->Display()->SetPickMode()"; + char pickmode[] = "((AliITSdisplay*)(gAlice->Display()))->SetPickMode()"; + Float_t db = 0.09; + fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db); + fPickButton->SetFillColor(38); + fPickButton->Draw(); + //char zoommode[] = "gAlice->Display()->SetZoomMode()"; + char zoommode[] = "((AliITSdisplay*)(gAlice->Display()))->SetZoomMode()"; + fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db); + fZoomButton->SetFillColor(38); + fZoomButton->Draw(); + fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db); + fArcButton->SetFillColor(kGreen); + fArcButton->Draw(); + //char butUnzoom[] = "gAlice->Display()->UnZoom()"; + char butUnzoom[] = "((AliITSdisplay*)(gAlice->Display()))->UnZoom()"; + TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15); + button->SetFillColor(38); + button->Draw(); + AppendPad(); // append display object as last object to force selection + + fCanvas->cd(); + fCanvas->Update(); + */ + + CreateModuleCanvas(size); + +} + +//_____________________________________________________________________________ +void AliITSdisplay::CreateModuleCanvas(Int_t size) +{ + + // Initialize display default parameters + SetRange(3.5,3.5); + // Create colors + CreateColors(); + // Create display canvas + Int_t ysize = size; + if (ysize < 100) ysize = 750; + Int_t xsize = Int_t(size*830./ysize); + fCanvas = new TCanvas("ModuleCanvas", "ITS Clusters Display",14,47,xsize,ysize); + fCanvas->ToggleEventStatus(); + + Int_t wtopx, wtopy; + UInt_t ww,wh; + fCanvas->GetCanvasPar(wtopx,wtopy,ww,wh); + + Float_t cx = gStyle->GetScreenFactor(); + + printf("CreateCanvas: cx wtopx wtopy ww wh %f %d %d %d %d\n", cx,wtopx,wtopy,ww,wh); + + Int_t dum1,dum2; + UInt_t fCw,fCh; + + Int_t fCanvasID=fCanvas->GetCanvasID(); + gVirtualX->GetGeometry(fCanvasID, dum1, dum2, fCw, fCh); + + printf("CreateCanvas: fCw, fCh %d %d \n", fCw, fCh ); + + + + // Create main display pad + fPad = new TPad("mviewpad", "ITS display",0.15,0,0.9,1); + fPad->Draw(); + fPad->Modified(); + fPad->SetFillColor(1); + fPad->SetBorderSize(2); + + fCanvas->cd(); + + // Create colors pad + fColPad = new TPad("colpad", "Colors pad",0.9,0,1,1); + fColPad->Draw(); + fColPad->Modified(); + fColPad->SetFillColor(19); + fColPad->SetBorderSize(2); + fColPad->cd(); + DisplayColorScale(); + + fCanvas->cd(); + + // Create user interface control pad + DisplayButtons(); + fCanvas->cd(); + + // Create Range and mode pad + Float_t dxtr = 0.15; + Float_t dytr = 0.45; + fTrigPad = new TPad("mtrigger", "range and mode pad",0,0,dxtr,dytr); + fTrigPad->SetEditable(kFALSE); + fTrigPad->Draw(); + fTrigPad->cd(); + fTrigPad->SetFillColor(22); + fTrigPad->SetBorderSize(2); + fRangeSlider = new TSlider("mrange","range",0.7,0.42,0.9,0.98); + fRangeSlider->SetObject(this); + + // to use "gAlice->Display()->SetPickMode()" KEEP "trigger" instead + // of "mtrigger" and "range" instead of "mrange" !!!! - do NOT change + // the pad names if mix methods from AliDisplay and AliITSdisplay ! + + //char pickmode[] = "gAlice->Display()->SetPickMode()"; + char pickmode[] = "((AliITSdisplay*)(gAlice->Display()))->SetPickMode()"; + Float_t db = 0.09; + fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db); + fPickButton->SetFillColor(38); + fPickButton->Draw(); + //char zoommode[] = "gAlice->Display()->SetZoomMode()"; + char zoommode[] = "((AliITSdisplay*)(gAlice->Display()))->SetZoomMode()"; + fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db); + fZoomButton->SetFillColor(38); + fZoomButton->Draw(); + fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db); + fArcButton->SetFillColor(kGreen); + fArcButton->Draw(); + //char butUnzoom[] = "gAlice->Display()->UnZoom()"; + char butUnzoom[] = "((AliITSdisplay*)(gAlice->Display()))->UnZoom()"; + TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15); + button->SetFillColor(38); + button->Draw(); + AppendPad(); // append display object as last object to force selection + + fCanvas->cd(); + fCanvas->Update(); +} + + +//_____________________________________________________________________________ +AliITSdisplay::~AliITSdisplay() +{ + // Delete space point structure + if (fPoints) fPoints->Delete(); + delete fPoints; + fPoints = 0; + // + if (fPhits) fPhits->Delete(); + delete fPhits; + fPhits = 0; + // + if (fRpoints) fRpoints->Delete(); + delete fRpoints; + fRpoints = 0; +// + if (fR2points) fR2points->Delete(); + delete fR2points; + fR2points = 0; +// + if (fCpoints) fCpoints->Delete(); + delete fCpoints; + fCpoints = 0; +} + +//_____________________________________________________________________________ +void AliITSdisplay::Clear(Option_t *) +{ +// Delete graphics temporary objects +} + +//_____________________________________________________________________________ +void AliITSdisplay::DisplayButtons() +{ +// Create the user interface buttons + + + fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1); + fButtons->SetEditable(kFALSE); + fButtons->Draw(); + fButtons->SetFillColor(38); + fButtons->SetBorderSize(2); + fButtons->cd(); + +// Int_t butcolor = 33; + Float_t dbutton = 0.08; + Float_t y = 0.96; + Float_t dy = 0.014; + Float_t x0 = 0.05; + Float_t x1 = 0.95; + + TButton *button; + char but1[] = "((AliITSdisplay*)(gAlice->Display()))->ShowNextEvent(1)"; + button = new TButton("Next",but1,x0,y-dbutton,x1,y); + button->SetFillColor(38); + button->Draw(); + + y -= dbutton +dy; + //char but2[] = "gAlice->Display()->ShowNextEvent(-1)"; + char but2[] = "((AliITSdisplay*)(gAlice->Display()))->ShowNextEvent(-1)"; + button = new TButton("Previous",but2,x0,y-dbutton,x1,y); + button->SetFillColor(38); + button->Draw(); + + y -= dbutton + dy; + char but3[] = "((AliITSdisplay*)(gAlice->Display()))->NextModule(1)"; + button = new TButton("Module +", but3, x0, y - dbutton, x1, y); + button->SetFillColor(38); + button->Draw(); + + y -= dbutton + dy; + char but4[] = "((AliITSdisplay*)(gAlice->Display()))->NextModule(-1)"; + button = new TButton("Module -", but4, x0, y - dbutton, x1, y); + button->SetFillColor(38); + button->Draw(); + + y -= dbutton + dy; + char but5[] = "((AliITSdisplay*)(gAlice->Display()))->DrawHistograms()"; + button = new TButton("DrawHist", but5, x0, y - dbutton, x1, y); + button->SetFillColor(38); + button->Draw(); + /* + y -= dbutton +dy; + char but6[] = "((AliITSdisplay*)(gAlice->Display()))->Trigger()"; + button = new TButton("Trigger",but6,x0,y-dbutton,x1,y); + button->SetFillColor(38); + button->Draw(); + */ + // display logo + TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22); + diamond->SetFillColor(50); + diamond->SetTextAlign(22); + diamond->SetTextColor(5); + diamond->SetTextSize(0.11); + diamond->Draw(); + diamond->AddText(".. "); + diamond->AddText("ROOT"); + diamond->AddText("ITS"); + diamond->AddText("... "); + diamond->AddText(" "); +} + +//_____________________________________________________________________________ +void AliITSdisplay::CreateColors() +{ +// Create the colors palette used to display clusters + + Int_t k,i; + Int_t color; + Float_t r,g,b; + + for (k=1;k<=5;k++) { + switch(k) { + case 1: + for (i=1;i<=5;i++) { + r=1.; + g=i*0.2; + b=0.; + color=i; + color=260+23-color; + new TColor(color,r,g,b); + } + break; + case 2: + for (i=1;i<=4;i++) { + r=1.1-i*0.2; + g=1.; + b=0.; + color=i+5; + color=260+23-color; + new TColor(color,r,g,b); + } + break; + case 3: + for (i=1;i<=4;i++) { + r=0.; + g=1.; + b=i*0.2+0.2; + color=i+9; + color=260+23-color; + new TColor(color,r,g,b); + } + break; + case 4: + for (i=1;i<=4;i++) { + r=0.; + g=1.1-i*0.2; + b=1.; + color=i+13; + color=260+23-color; + new TColor(color,r,g,b); + } + break; + case 5: + for (i=1;i<=5;i++) { + r=i*0.2; + g=0.; + b=1.; + color=i+17; + color=260+23-color; + new TColor(color,r,g,b); + } + break; + } + + } + +} + +//_____________________________________________________________________________ +void AliITSdisplay::DisplayColorScale() +{ + + Int_t i; + Int_t color; + Float_t xlow, ylow, xup, yup, hs; + Float_t x1, y1, x2, y2; + x1 = y1 = 0; + x2 = y2 = 20; + + printf("DisplayColorScale - gPad %p\n",gPad); + + /* + gPad->SetFillColor(0); + gPad->Clear(); + gPad->Range(x1,y1,x2,y2); + */ + + fColPad->SetFillColor(0); + fColPad->Clear(); + fColPad->Range(x1,y1,x2,y2); + + TText *text = new TText(0,0,""); + text->SetTextFont(61); + text->SetTextSize(0.2); + text->SetTextAlign(22); + + /* + AliMUON *MUON = (AliMUON*)gAlice->GetModule("MUON"); + AliMUONchamber *iChamber = &(MUON->Chamber(fChamber-1)); + AliMUONresponse * response=iChamber->GetResponseModel(); + Int_t adcmax= (Int_t) response->MaxAdc(); + */ + + Int_t adcmax=1024; + + + TBox *box; + char label[8]; +//*-* draw colortable boxes + hs = (y2-y1)/Float_t(22); + xlow=x1+1; + xup=x2-9; + for (i=0;i<22;i++) { + ylow = y1 + hs*(Float_t(i)); + yup = y1 + hs*(Float_t(i+1)); + color = 261+i; + Double_t logscale=Double_t(i+1)*(TMath::Log(adcmax)/22); + Int_t scale=(Int_t)TMath::Exp(logscale); + sprintf(label,"%d",scale); + box = new TBox(xlow, ylow, xup, yup); + box->SetFillColor(color); + box->Draw(); + text->DrawText(xup+4, 0.5*(ylow+yup),label); + } +} + +//______________________________________________________________________________ +Int_t AliITSdisplay::DistancetoPrimitive(Int_t px, Int_t) +{ +// Compute distance from point px,py to objects in event + + gPad->SetCursor(kCross); + + if (gPad == fTrigPad) return 9999; + + const Int_t big = 9999; + Int_t dist = big; + Float_t xmin = gPad->GetX1(); + Float_t xmax = gPad->GetX2(); + Float_t dx = 0.02*(xmax - xmin); + Float_t x = gPad->AbsPixeltoX(px); + if (x < xmin+dx || x > xmax-dx) return dist; + + if (fZoomMode) return 0; + else return 7; +} + +//_____________________________________________________________________________ +void AliITSdisplay::Draw(Option_t *) +{ +// Display current event + + printf("Draw\n"); + + fPad->cd(); + + DrawView(fTheta, fPhi, fPsi); + // Display the event number and title + fPad->cd(); + DrawTitle(); +} + + +//_____________________________________________________________________________ +void AliITSdisplay::DrawClusters() +{ +// Draw clusters for ITS modules + + if (!fDrawClusters) return; + + Int_t ndigits, digit; + TObjArray *points; + AliITSpoints *pm; + + LoadDigits(fModule); + + fClustersCuts = 0; + points = Points(); + if (!points) return; + ndigits = points->GetEntriesFast(); + for (digit=0;digitUncheckedAt(digit); + if (!pm) continue; + Float_t *pxyz; + pxyz=pm->GetP(); + TMarker3DBox *marker=pm->GetMarker(0); + if (marker) marker->Draw(); + pm->Draw(); + fClustersCuts +=pm->GetN(); + + } + + sModule=fModule; +} + +//_____________________________________________________________________________ +void AliITSdisplay::DrawHits() +{ +// Draw hits for ITS modules + + LoadHits(fModule); + + Int_t ntracks, track; + TObjArray *points; + AliITSpoints *pm; + + fHitsCuts = 0; + points = Phits(); + if (!points) return; + ntracks = points->GetEntriesFast(); + for (track=0;trackUncheckedAt(track); + if (!pm) continue; + pm->Draw(); + fHitsCuts += pm->GetN(); + } +} + + +//_____________________________________________________________________________ +void AliITSdisplay::DrawCoG() +{ +// Draw rec hits for ITS module + + /* + if (!fDrawCoG) return; + LoadCoG(fChamber,fCathode); + + Int_t ncog, icog; + TObjArray *points; + AliITSpoints *pm; + + points = Rpoints(); + if (!points) return; + ncog = points->GetEntriesFast(); + for (icog=0;icogUncheckedAt(icog); + if (!pm) continue; + pm->Draw(); + } + */ +} +//_____________________________________________________________________________ +void AliITSdisplay::DrawCoG2() +{ +// Draw rec hits for ITS module + + /* + + if (!fDrawCoG) return; + + + if (fCathode==1) { + LoadCoG2(fChamber,2); + } else if (fCathode==2) { + LoadCoG2(fChamber,1); + } + + Int_t ncog, icog; + TObjArray *points; + AliITSpoints *pm; + + points = R2points(); + if (!points) return; + ncog = points->GetEntriesFast(); + for (icog=0;icogUncheckedAt(icog); + if (!pm) continue; + pm->Draw(); + } + */ +} +//_____________________________________________________________________________ +void AliITSdisplay::DrawCathCor() +{ +// Draw hits for ITS chambers + + /* + + if (!fDrawCathCor) return; + + LoadCathCor(fChamber); + + Int_t ncog, icog; + TObjArray *points; + AliITSpoints *pm; + + points = Cpoints(); + if (!points) return; + ncog = points->GetEntriesFast(); + for (icog=0;icogUncheckedAt(icog); + if (!pm) continue; + pm->Draw(); + } + */ +} + +//_____________________________________________________________________________ +void AliITSdisplay::DrawTitle(Option_t *option) +{ +// Draw the event title + + Float_t xmin = gPad->GetX1(); + Float_t xmax = gPad->GetX2(); + Float_t ymin = gPad->GetY1(); + Float_t ymax = gPad->GetY2(); + Float_t dx = xmax-xmin; + Float_t dy = ymax-ymin; + + if (strlen(option) == 0) { + TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy); + title->SetBit(kCanDelete); + title->SetFillColor(42); + title->Draw(); + char ptitle[100]; + sprintf(ptitle,"Alice event: %d, Run:%d Module:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun(),fModule); + title->AddText(ptitle); + Int_t nparticles = gAlice->Particles()->GetEntriesFast(); + sprintf(ptitle,"Nparticles = %d Nhits = %d Npads fired = %d",nparticles, fHitsCuts,fClustersCuts); + title->AddText(ptitle); + } else { + TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option); + label->SetBit(kCanDelete); + label->SetFillColor(42); + label->Draw(); + } +} + +//_____________________________________________________________________________ +void AliITSdisplay::DrawView(Float_t theta, Float_t phi, Float_t psi) +{ +// Draw a view of ITS clusters + + printf("DrawView - fPad gPad %p %p\n",fPad,gPad); + + gPad->SetCursor(kWatch); + gPad->SetFillColor(1); + gPad->Clear(); + gPad->SetFillColor(1); + + Int_t iret=0; + TView *view = new TView(1); + + printf("DrawView - view %p \n",view); + + Float_t range = fRrange*fRangeSlider->GetMaximum(); + + printf("DrawView - range fRrange fRangeSlider %f %f %f \n",range,fRrange,fRangeSlider->GetMaximum()); + view->SetRange(-range,-range,-range,range, range, range); + fZoomX0[0] = -1; + fZoomY0[0] = -1; + fZoomX1[0] = 1; + fZoomY1[0] = 1; + fZooms = 0; + +// Display ITS Chamber Geometry +// gAlice->GetGeometry()->Draw("same"); + char NodeName[7]; + sprintf(NodeName,"ITS%d",100+fModule); + printf("Node name %s\n", NodeName); + + TNode *node1=gAlice->GetGeometry()->GetNode(NodeName); + if (node1) node1->Draw("same"); + +//add clusters to the pad + DrawClusters(); + DrawHits(); + //DrawCoG(); + // DrawCoG2(); + //DrawCathCor(); + + printf("DrawView - before append fPad gPad %p %p\n",fPad,gPad); + // add itself to the list (must be last) + AppendPad(); + view->SetView(phi, theta, psi, iret); +} + + +//______________________________________________________________________________ +void AliITSdisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py) +{ +// Execute action corresponding to the mouse event + + static Float_t x0, y0, x1, y1; + + static Int_t pxold, pyold; + static Int_t px0, py0; + static Int_t linedrawn; + Float_t temp; + + + /* + //printf("ExecuteEvent - px py %d %d\n",px,py); + + int px1 = gPad->GetEventX(); + int py1 = gPad->GetEventY(); + float uxmin = gPad->GetUxmin(); + float uxmax = gPad->GetUxmax(); + int pxmin = gPad->XtoAbsPixel(uxmin); + int pxmax = gPad->XtoAbsPixel(uxmax); + + //printf("ExecuteEvent - px1 py1 uxmin uxmax pxmin pxmax %d %d %f %f %d %d\n",px1,py1,uxmin,uxmax,pxmin,pxmax); + + Float_t x = gPad->AbsPixeltoX(px); + Float_t y = gPad->AbsPixeltoY(py); + //printf("x=%.3g, y=%.3g \n",gPad->PadtoX(x),gPad->PadtoY(y)); + + TObject *select = gPad->GetSelected(); + if(!select) {printf("no select \n"); return;} + if (select->InheritsFrom("AliITSdisplay")) printf("Inherits from AliITSdisplay \n"); + + if (select->InheritsFrom("TCanvas")) printf("Inherits from TCanvas \n"); + if (select->InheritsFrom("TView")) printf("Inherits from TView \n"); + + Float_t x,y; + + // x,y in the -1,1 scale + x = gPad->AbsPixeltoX(px); + y = gPad->AbsPixeltoY(py); + + printf("abspixeltoX: px py %d %d x=%.3g, y=%.3g \n",px,py,x,y); + printf("x=%.3g, y=%.3g \n",gPad->PadtoX(x),gPad->PadtoY(y)); + + // it should be smth like ? - no ! + x = gPad->AbsPixeltoX(px)*fRrange*fRangeSlider->GetMaximum(); + y = gPad->AbsPixeltoY(py)*fRrange*fRangeSlider->GetMaximum(); + // now find out how to convert these x,y to x,y in detector system + + Int_t dum1,dum2; + UInt_t fCw, fCh; + Float_t fYsizeReal, fXsizeReal; + + Int_t fCanvasID=fCanvas->GetCanvasID(); + gVirtualX->GetGeometry(fCanvasID, dum1, dum2, fCw, fCh); + + printf("Exec: fCw, fCh %d %d \n", fCw, fCh ); + + if (fCw < fCh) { + fYsizeReal = 20; + fXsizeReal = fYsizeReal*Float_t(fCw)/Float_t(fCh); + } + else { + fXsizeReal = 20; + fYsizeReal = fXsizeReal*Float_t(fCh)/Float_t(fCw); + } + + printf("Exec: fYsizeReal, fXsizeReal %f %f \n",fYsizeReal, fXsizeReal); + + fXsizeReal = fXsizeReal*Float_t(px)/Float_t(fCw); + fYsizeReal = fYsizeReal*Float_t(py)/Float_t(fCh); + + printf("Exec: fYsizeReal, fXsizeReal %f %f \n",fYsizeReal, fXsizeReal); + + */ + + if (!gPad) return; + + Float_t scale[3],center[3]; + Int_t irep; + gPad->GetView()->FindScope(scale,center,irep); + for(int i=0;i<3;i++) { + //printf("Exec: scale center irep %f %f %d \n",scale[i],center[i],irep); + } + Float_t x,y; + // x,y in the -1,1 scale + x = gPad->AbsPixeltoX(px); + y = gPad->AbsPixeltoY(py); + Float_t xhit=x*scale[0]/(fRrange*fRangeSlider->GetMaximum()); + Float_t yhit=y*scale[0]/(fRrange*fRangeSlider->GetMaximum()); + //printf("Exec: x*scale y*scale xhit yhit%f %f %f %f \n",x*scale[0],y*scale[1],xhit,yhit); + + Int_t anode, timebin; + GetPadIxy(anode,timebin,x*scale[0],y*scale[0]); + //printf("Exec: anode timebin %d %d \n",anode,timebin); + + + if (px == 0 && py == 0) { //when called by sliders + if (event == kButton1Up) { + Draw(); + } + return; + } + if (!fZoomMode && gPad->GetView()) { + gPad->GetView()->ExecuteRotateView(event, px, py); + return; + } + + // something to zoom ? + gPad->SetCursor(kCross); + + switch (event) { + + case kButton1Down: + gVirtualX->SetLineColor(-1); + gPad->TAttLine::Modify(); //Change line attributes only if necessary + x0 = gPad->AbsPixeltoX(px); + y0 = gPad->AbsPixeltoY(py); + px0 = px; py0 = py; + pxold = px; pyold = py; + linedrawn = 0; + return; + + case kButton1Motion: + if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow); + pxold = px; + pyold = py; + linedrawn = 1; + gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow); + return; + + case kButton1Up: + gPad->GetCanvas()->FeedbackMode(kFALSE); + if (px == px0) return; + if (py == py0) return; + x1 = gPad->AbsPixeltoX(px); + y1 = gPad->AbsPixeltoY(py); + + if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;} + if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;} + gPad->Range(x0,y0,x1,y1); + if (fZooms < kMAXZOOM-1) { + fZooms++; + fZoomX0[fZooms] = x0; + fZoomY0[fZooms] = y0; + fZoomX1[fZooms] = x1; + fZoomY1[fZooms] = y1; + } + gPad->Modified(kTRUE); + return; + } + +} +//___________________________________________ +void AliITSdisplay::LoadDigits(Int_t module) +{ +// Read digits info and store x,y,z info in arrays fPoints + + printf("LoadDigits - fZooms %d\n",fZooms); + + if (module > fNmodules ) return; + + fModule=module; + + ResetPoints(); + + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + AliITSgeom *geom = ITS->GetITSgeom(); + + // get detector type + AliITSDetType *iDetType = ITS->DetType(fLayer); + Int_t id=(Int_t)((fLayer-1)/2); + + // for the moment do only SDD + if (id != 1) return; + + TClonesArray *ITSdigits = ITS->DigitsAddress(id); + if (ITSdigits == 0) return; + + Int_t nent=(Int_t)gAlice->TreeD()->GetEntries(); + printf("Entries in TreeD - nent %d\n",nent); + Int_t lastSPD=geom->GetLastSPD(); + Int_t lastSDD=geom->GetLastSDD(); + if (nent < lastSDD) { + printf("You have not done the digitisation for all det types !!!"); + module=fModule-lastSPD; + } + + + ITS->ResetDigits(); + gAlice->TreeD()->GetEvent(module); + //gAlice->TreeD()->GetEvent(nent-nofmodules+module-1); + Int_t ndigits = ITSdigits->GetEntriesFast(); + printf("Found %d digits for module %d in det type %d \n",ndigits,fModule,id+1); + if (ndigits == 0) return; + if (fPoints == 0) fPoints = new TObjArray(ndigits); + + //AliITSresponseV0* resp = (AliITSresponseV0*)iDetType->GetResponseModel(); + AliITSresponse* resp = (AliITSresponse*)iDetType->GetResponseModel(); + resp->SetDetSize(38400,75200); + resp->SetDetParam(376,256,40.,6.); + + if (!fMap) fMap = new AliITSMapA2(resp); + if (sModule != fModule) fMap->ClearMap(); + + + // if parameters in response where changed during digitisation set these + // parameters here as well !! resp->SetDetParam(....), SetDetSize(...) + // or pass in the constructor of display the pointer to a response + // instantiation done in ITSdisplay.C ! + + AliITSdigitSDD *mdig; + AliITSpoints *points = 0; + TMarker3DBox *marker=0; + Float_t xl[3], dx[3]; + // + //loop over all digits and store their position + Int_t adcsatm=1024; + Int_t npoints=1; + for (Int_t digit=0;digitUncheckedAt(digit); + // + // First get all needed parameters + // + Int_t charge=0; + Int_t chargecolor=0; + Int_t signal=mdig->fSignal; + for (int i=0;i<3;i++) {charge += mdig->fTcharges[i];} + //printf("charge %d\n",charge); + Int_t chargeindex=Int_t(TMath::Log(charge)/(TMath::Log(adcsatm)/22)); + Int_t index=Int_t(TMath::Log(signal)/(TMath::Log(adcsatm)/22)); + Int_t color=261+index; + if (color>282) color=282; + if (charge) chargecolor=261+chargeindex; + if (chargecolor>282) chargecolor=282; + Int_t anode=mdig->fCellX ; + Int_t timebin=mdig->fCellY; + fMap->SetHit(anode,timebin,(Double_t)signal); + // get the center of the pad - add on x and y half of pad size + GetPadCxy(anode,timebin,xl,dx); + + Float_t xpad=xl[0]; + Float_t ypad=xl[1]; + Float_t zpad=xl[2]; + + Float_t dpx=dx[0]; + Float_t dpy=dx[1]; + Float_t dpz=dx[2]; + + //printf("anode timebin charge signal %d %d %d %d \n",anode, timebin,charge,signal); + //printf("xpad ypad zpad %f %f %f\n",xpad,ypad,zpad); + //printf(" dpx dpz %f %f \n",dpx,dpz); + // + // Then set the objects + // + points = new AliITSpoints(npoints); + fPoints->AddAt(points,digit); + + points->SetMarkerColor(color); + points->SetMarkerStyle(21); + //points->SetMarkerSize(0.5); + points->SetMarkerSize(0.7); + points->SetParticle(-1); + points->SetDigitIndex(digit); + points->SetPoint(0,xpad,ypad,zpad); + marker=new TMarker3DBox(xpad,ypad,zpad,dpx,dpy,dpz,0,0); + //marker->SetLineColor(2); + marker->SetLineColor(chargecolor); + marker->SetFillStyle(1001); + marker->SetFillColor(color); + marker->SetRefObject((TObject*)points); + points->Set3DMarker(0, marker); + + } +} +//___________________________________________ +void AliITSdisplay::GetPadCxy(Int_t anode, Int_t timebin, Float_t *xl, Float_t *dx ) + +{ + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + // get detector type + AliITSDetType *iDetType = ITS->DetType(fLayer); + AliITSresponse* resp = (AliITSresponse*)iDetType->GetResponseModel(); + + + Int_t na,ns; + Float_t clock, speed; + resp->GetDetParam(na,ns,clock,speed); + //printf("resp na ns clock speed %p %d %d %f %f\n",resp,na,ns,clock,speed); + + Float_t timestep=1000./clock; + Float_t pitch=resp->Pitch(); + Float_t width=resp->Width(); + Float_t length=resp->Length(); + //printf("timestep pitch width length %f %f %f %f \n",timestep,pitch,width,length); + + const Float_t kconv=10000; // um->cm + + + //Float_t driftpath=timebin*timestep*speed; + Float_t driftpath=(timebin+1)*timestep*speed; + if (anode >= na) xl[0]=(length-driftpath)/kconv; + else xl[0]= -(length-driftpath)/kconv; + if (anode >= na) anode-=na; + //xl[2]=(anode*pitch-width/2)/kconv; + xl[2]=((anode+1)*pitch-width/2)/kconv; + xl[1]=fYmodule; + //printf("anode timebin %d %d \n",anode,timebin); + //printf("anode*pitch timebin*timestep*speed %f %f\n",anode*pitch,timebin*timestep*speed); + + // keep these for drawing + //dx[0]=timestep*speed/kconv/2.1; + //dx[1]=0; + //dx[2]=pitch/kconv/2.05; + + dx[0]=timestep*speed/kconv/2; + dx[1]=0; + dx[2]=pitch/kconv/2; +} + +//___________________________________________ +void AliITSdisplay::GetPadIxy(Int_t &anode, Int_t &timebin,Float_t x,Float_t z) +{ + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + // get detector type + AliITSDetType *iDetType = ITS->DetType(fLayer); + AliITSresponse* resp = (AliITSresponse*)iDetType->GetResponseModel(); + + + Int_t na,ns; + Float_t clock, speed; + resp->GetDetParam(na,ns,clock,speed); + + Float_t timestep=1000./clock; + Float_t pitch=resp->Pitch(); + Float_t width=resp->Width(); + Float_t length=resp->Length(); + + const Float_t kconv=10000; // cm->um + + Float_t driftpath=length-TMath::Abs(kconv*x); + timebin=(Int_t)(driftpath/speed/timestep); + anode=kconv*z/pitch + na/2; + if (x > 0) anode += na; + + timebin+=1; + anode+=1; + //printf("anode timebin %d %d\n",anode,timebin); + +} +//___________________________________________ +void AliITSdisplay::LoadCoG(Int_t chamber, Int_t cathode) +{ +// Read raw clusters info and store x,y,z info in arrays fRpoints +// Loop on all detectors + + /* + + if (chamber > 10) return; + + ResetRpoints(); + + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + AliITSchamber* iChamber; + + TClonesArray *ITSrawclust = ITS->RawClustAddress(chamber-1); + if (ITSrawclust == 0) return; + + ITS->ResetRawClusters(); + + + Int_t nent=(Int_t)gAlice->TreeR()->GetEntries(); + gAlice->TreeR()->GetEvent(nent-2+cathode-1); + //gAlice->TreeR()->GetEvent(cathode); + Int_t nrawcl = ITSrawclust->GetEntriesFast(); + if (nrawcl == 0) return; + if (fRpoints == 0) fRpoints = new TObjArray(nrawcl); + + iChamber = &(ITS->Chamber(chamber-1)); + Float_t zpos=iChamber->ZPosition(); + AliITSRawCluster *mRaw; + AliITSpoints *points = 0; + // + //loop over all raw clusters and store their position + points = new AliITSpoints(nrawcl); + for (Int_t iraw=0;irawUncheckedAt(iraw); + fRpoints->AddAt(points,iraw); + points->SetMarkerColor(51); + points->SetMarkerStyle(2); + points->SetMarkerSize(1.); + points->SetParticle(-1); + points->SetHitIndex(-1); + points->SetTrackIndex(-1); + points->SetDigitIndex(-1); + points->SetPoint(iraw,mRaw->fX,mRaw->fY,zpos); + } + */ +} +//___________________________________________ +void AliITSdisplay::LoadCoG2(Int_t chamber, Int_t cathode) +{ +// Read raw clusters info and store x,y,z info in arrays fRpoints +// Loop on all detectors + /* + + if (chamber > 10) return; + + ResetR2points(); + + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + AliMUONchamber* iChamber; + + TClonesArray *MUONrawclust = MUON->RawClustAddress(chamber-1); + if (MUONrawclust == 0) return; + + MUON->ResetRawClusters(); + + Int_t nent=(Int_t)gAlice->TreeR()->GetEntries(); + gAlice->TreeR()->GetEvent(nent-2+cathode-1); + //gAlice->TreeR()->GetEvent(cathode); + Int_t nrawcl = MUONrawclust->GetEntriesFast(); + if (nrawcl == 0) return; + if (fR2points == 0) fR2points = new TObjArray(nrawcl); + + iChamber = &(MUON->Chamber(chamber-1)); + Float_t zpos=iChamber->ZPosition(); + AliMUONRawCluster *mRaw; + AliMUONpoints *points = 0; + // + //loop over all raw clusters and store their position + points = new AliMUONpoints(nrawcl); + for (Int_t iraw=0;irawUncheckedAt(iraw); + fR2points->AddAt(points,iraw); + points->SetMarkerColor(51); + points->SetMarkerStyle(4); + points->SetMarkerSize(1.3); + points->SetParticle(-1); + points->SetHitIndex(-1); + points->SetTrackIndex(-1); + points->SetDigitIndex(-1); + points->SetPoint(iraw,mRaw->fX,mRaw->fY,zpos); + } + */ +} +//___________________________________________ +void AliITSdisplay::LoadCathCor(Int_t chamber) +{ +// Read correlation info and store x,y,z info in arrays fCpoints +// Loop on all detectors + + /* + if (chamber > 10) return; + fChamber=chamber; + ResetCpoints(); + + AliMUON *MUON = (AliMUON*)gAlice->GetModule("MUON"); + AliMUONchamber* iChamber; + iChamber = &(MUON->Chamber(chamber-1)); + Float_t zpos=iChamber->ZPosition(); // check with Andreas + + + //new + MUON->GetTreeC(fEvent); + TTree *TC=MUON->TreeC(); + if (!TC) return; + // Int_t nent=(Int_t)TC->GetEntries(); + + TClonesArray *MUONcorrel = MUON->CathCorrelAddress(chamber-1); + if (MUONcorrel == 0) return; + + MUON->ResetCorrelation(); + TC->GetEvent(); + + Int_t ncor = MUONcorrel->GetEntries(); + if (!ncor) return; + if (!fCpoints) fCpoints = new TObjArray(ncor); + + AliMUONcorrelation *mCor; + AliMUONpoints *points = 0; + // + //loop over all raw clusters and store their position + points = new AliMUONpoints(ncor); + for (Int_t icor=0;icorUncheckedAt(icor); + fCpoints->AddAt(points,icor); + points->SetMarkerColor(4); + points->SetMarkerStyle(4); + points->SetMarkerSize(0.8); + points->SetParticle(-1); + points->SetHitIndex(-1); + points->SetTrackIndex(-1); + points->SetDigitIndex(-1); + points->SetPoint(icor,mCor->fX[0],mCor->fY[0],zpos); + } + */ +} + +//___________________________________________ +void AliITSdisplay::LoadHits(Int_t module) +{ + +// Read hits info and store x,y,z info in arrays fPhits +// Loop on all detectors + + + if (module > fNmodules || fNmodules==0) return; + + fModule=module; + printf("LoadModuleHits - fModule module %d %d\n",fModule,module); + + ResetPhits(); + + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + AliITSgeom *geom = ITS->GetITSgeom(); + + // try fITSmodules first (memory) - check also TreeH with the condition + // if (module != fModule) continue; - see the speed + + TObjArray *mods = ITS->GetModules(); + Int_t nentries=(Int_t)mods->GetEntriesFast(); + printf("nentries %d\n",nentries); + + AliITSmodule *mod = (AliITSmodule *)mods->UncheckedAt(fModule); + TObjArray *fHits = mod->GetHits(); + Int_t nhits = fHits->GetEntriesFast(); + if (fPhits == 0) fPhits = new TObjArray(nhits); + printf("LoadModuleHits - fPhits fModule nhits %p %d %d\n",fPhits,fModule,nhits); + AliITSpoints *points = 0; + AliITShit *mHit = 0; + Int_t idtrack, idhit; + for (Int_t hit=0;hitUncheckedAt(hit); + mod->GetHitTrackAndHitIndex(hit,idtrack,idhit); + printf("hit eloss %d %f\n",hit,mHit->GetIonization()); + printf("layer ladder det %d %d %d\n",mHit->GetLayer(),mHit->GetLadder(),mHit->GetDetector()); + if (!mHit->GetIonization()) continue; + //fYmodule=mHit->fY; + Float_t xl[3], xg[3]; + xg[0]=mHit->fX; + xg[1]=mHit->fY; + xg[2]=mHit->fZ; + + geom->GtoL(fModule,xg,xl); + printf("hit xhit yhit zhit %d %f %f %f\n",hit,xl[0],xl[1],xl[2]); + Float_t x,y,z,tof; + mHit->GetPositionL(x,y,z,tof); + printf("hit x y z %d %f %f %f\n",hit,x,y,z); + + fYmodule=xl[1]; + // + // Retrieve info and set the objects + // + points = new AliITSpoints(); + points->SetMarkerColor(kRed); + points->SetMarkerStyle(5); + points->SetMarkerSize(1.); + points->SetParticle(mHit->fTrack); + points->SetHitIndex(idhit); + points->SetTrackIndex(idtrack); + //points->SetPoint(0,mHit->fX,mHit->fY,mHit->fZ); + points->SetPoint(0,xl[0],xl[1],xl[2]); + fPhits->AddAt(points,hit); + } + +} + +//_____________________________________________________________________________ +void AliITSdisplay::NextModule(Int_t delta) +{ + // to go from module to next module if delta = 1 + // or previous module otherwise + if (delta == 1) { + if (fModule < fNmodules) fModule++; + } else { + if (fModule > 1) fModule--; + } + if (!fPad) return; + fPad->Clear(); + Draw(); +} + +//_____________________________________________________________________________ +void AliITSdisplay::Paint(Option_t *) +{ +// Paint miscellaneous items + +} + +//_____________________________________________________________________________ +void AliITSdisplay::DrawHistograms() +{ + + // better write a class for this - see TInspectCanvas - with a methode + // called xxxx and here just do smth like it's done for Inspect() in TObject + //gROOT->ProcessLine(Form("TInspectCanvas::Inspector((TObject *)0x%lx);",(Long_t)this)); + // with xxxx instead of Inspector - so one can create buttons on the + // new canvas and have more choices + + + printf("DrawHistograms: fZooms fZoomMode %d %d ! \n",fZooms,fZoomMode); + + if (!fZooms) return; + + Float_t scale[3],center[3]; + Int_t irep; + gPad->GetView()->FindScope(scale,center,irep); + + Int_t amin, tmin, amax, tmax; + GetPadIxy(amin,tmin, fZoomX0[fZooms]*scale[0], fZoomY0[fZooms]*scale[0]); + printf("DrawHist: amin tmin %d %d \n",amin,tmin); + GetPadIxy(amax,tmax, fZoomX1[fZooms]*scale[0], fZoomY1[fZooms]*scale[0]); + printf("DrawHist: amax tmax %d %d \n",amax,tmax); + + if ((fZoomX0[fZooms] < 0 && fZoomX1[fZooms] > 0) || (fZoomX0[fZooms] > 0 && fZoomX1[fZooms] < 0) ) tmax=256; + + if( amax-amin > kMAXHIST) { + Error("DrawHistograms","Too many histograms %d! Zoom a smaller area and try again!",amax-amin); + return; + } + Int_t nbinx = amax-amin; + Int_t nbiny = tmax-tmin; + + fDrawHist = kTRUE; + TObjArray *fHis=0; + + //create or set the new canvas c2 + TVirtualPad *padsav = gPad; + TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2"); + /* + if(c2) { + if (fHis) { + fHis->Delete(); + delete fHis; + } + } + */ + if(c2) delete c2->GetPrimitive("h2map"); + else c2=new TCanvas("c2","c2",14,47,830,750); + c2->cd(); + + TPad *hpad = new TPad("hpad","",0.01,0.01,0.99,0.99); + hpad->SetFillColor(0); + //hpad->Draw(); + hpad->Divide(2,nbinx/2,0.,0.); + hpad->Draw(); + + char title[30], name[10]; + sprintf(title,"Signal map for module %d",fModule); + TH2F *fTH2F = new TH2F("h2map",title,nbinx,amin,amax,nbiny,tmin,tmax); + fHis=new TObjArray(nbinx); + + //TH1F *h1=new TH1F(" ","",nbiny,(float)tmin,(float)tmax); + + for (int i=amin;iReset(); + printf("i, i-amin %d %d \n",i,i-amin); + (*fHis)[i-amin] = new TH1F(" "," ",nbiny,(float)tmin,(float)tmax); + //sprintf(title,"Projection on anode=%d",i); + sprintf(title,"anode=%d",i); + sprintf(name,"h%d",i); + ((TH1F*)((*fHis)[i-amin]))->SetTitle(title); + ((TH1F*)((*fHis)[i-amin]))->SetTitleSize(2.); + ((TH1F*)((*fHis)[i-amin]))->SetTitleOffset(2.); + ((TH1F*)((*fHis)[i-amin]))->SetLabelSize(0.05); + //((TH1F*)((*fHis)[i-amin]))->SetYTitle(title); + ((TH1F*)((*fHis)[i-amin]))->SetName(name); + ((TH1F*)((*fHis)[i-amin]))->SetStats(0); + //h1->SetTitle(title); + //h1->SetTitleSize(0.04); + //h1->SetYTitle(title); + //h1->SetName(title); + hpad->cd(i-amin+1); + for (int j=tmin;jFill((float)j,(float)fMap->GetSignal(i,j)); + //h1->Fill((float)j,(float)fMap->GetSignal(i,j)); + fTH2F->Fill((float)i,(float)j,(float)fMap->GetSignal(i,j)); + } + ((TH1F*)((*fHis)[i-amin]))->Smooth(1); + //((TH1F*)((*fHis)[i-amin]))->Fit("gaus","ql"); + ((TH1F*)((*fHis)[i-amin]))->Draw(); + //h1->Fit("gaus","ql"); + //h1->Draw(); + //hpad->Update(); + } + c2->Update(); + //c2->SetFillColor(1); + //fTH2F->Draw("LEGO2"); + + padsav->cd(); + + fDrawHist=kFALSE; + + /* + if (fHis) { + fHis->Delete(); + delete fHis; + } + + */ + + + /* + //create or set the new canvas c2 + TVirtualPad *padsav = gPad; + TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2"); + if(c2) delete c2->GetPrimitive("Projection"); + if(c2) delete c2->GetPrimitive("h2map"); + else c2=new TCanvas("c2","c2",14,47,830,750); + c2->cd(); + + c2->SetFillColor(1); + fTH2F->Draw("LEGO2"); + + TPad *hpad = new TPad("hpad","",0.01,0.01,0.99,0.99); + hpad->SetFillColor(11); + hpad->Divide(1,nbinx/2,0.,0.); + hpad->Draw(); + // -empty projections !! + + //draw slice corresponding to mouse position + for(int i=amin;icd(i-amin+1); + //Int_t biny = fTH2F->GetYaxis()->FindBin(y); + //TH1D *hp = fTH2F->ProjectionX("",biny,biny); + TH1D *hp = fTH2F->ProjectionY("",i,i); + char title[80]; + sprintf(title,"Projection on anode=%d",i); + hp->SetName("Projection"); + hp->SetTitle(title); + //hp->Fit("gaus","ql"); + hp->Draw(); + hpad->Update(); + } + c2->Update(); + padsav->cd(); + + fDrawHist=kFALSE; + */ +} + +//_____________________________________________________________________________ +void AliITSdisplay::SetPickMode() +{ + fZoomMode = 0; + + fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC()); + fTrigPad->Modified(); +} + +//_____________________________________________________________________________ +void AliITSdisplay::SetZoomMode() +{ + fZoomMode = 1; + + fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC()); + fTrigPad->Modified(); +} + +//_____________________________________________________________________________ +void AliITSdisplay::SetModule(Int_t layer, Int_t ladder, Int_t detector) +{ +// Set chamber and cathode number + fLayer = layer; + fLadder = ladder; + fDetector = ladder; + + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + AliITSgeom *gm=ITS->GetITSgeom(); + fModule=gm->GetModuleIndex(fLayer,fLadder,fDetector); + + if (!fPad) return; + fPad->Clear(); + Draw(); +} + +//_____________________________________________________________________________ +void AliITSdisplay::SetModuleNumber(Int_t module) +{ +// Set chamber and cathode number + fModule=module; + + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + AliITSgeom *gm=ITS->GetITSgeom(); + gm->GetModuleId(fModule,fLayer,fLadder,fDetector); + + if (!fPad) return; + fPad->Clear(); + Draw(); +} +//_____________________________________________________________________________ +void AliITSdisplay::SetRange(Float_t rrange, Float_t zrange) +{ +// Set view range along R and Z + fRrange = rrange; + fZrange = zrange; + + if (!fPad) return; + fPad->Clear(); + Draw(); +} + +//_____________________________________________________________________________ +void AliITSdisplay::SetView(Float_t theta, Float_t phi, Float_t psi) +{ +// change viewing angles for current event + + fPad->cd(); + fPhi = phi; + fTheta = theta; + fPsi = psi; + Int_t iret = 0; + + TView *view = gPad->GetView(); + printf("SetView view %p \n",view); + if (view) view->SetView(fPhi, fTheta, fPsi, iret); + Draw(); + //else Draw(); + + gPad->Modified(); +} + +//_____________________________________________________________________________ +void AliITSdisplay::ShowNextEvent(Int_t delta) +{ +// Display (current event_number+delta) +// delta = 1 shown next event +// delta = -1 show previous event + if (delta) { + gAlice->Clear(); + Int_t current_event = gAlice->GetHeader()->GetEvent(); + Int_t new_event = current_event + delta; + gAlice->GetEvent(new_event); + fEvent=new_event; + if (!gAlice->TreeD() || !gAlice->TreeD() ) return; + } + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + ITS->ClearModules(); + ITS->InitModules(-1,fNmodules); + ITS->FillModules(fEvent,0,fNmodules," "," "); //memory problems ? + + fPad->cd(); + Draw(); +} + +//_____________________________________________________________________________ + +void AliITSdisplay::SetEvent(Int_t newevent) +{ + gAlice->GetEvent(newevent); + fEvent=newevent; + if (!gAlice->TreeD() || !gAlice->TreeD() ) return; + if (!fPad) return; + AliITS *ITS = (AliITS*)gAlice->GetModule("ITS"); + ITS->ClearModules(); + ITS->InitModules(-1,fNmodules); + ITS->FillModules(fEvent,0,fNmodules," "," "); //memory problems ? + fPad->cd(); + fPad->Clear(); + Draw(); + +} +//______________________________________________________________________________ +void AliITSdisplay::UnZoom() +{ + printf("UnZoom - fZooms %d\n",fZooms); + if (fZooms <= 0) return; + fZooms--; + TPad *pad = (TPad*)gPad->GetPadSave(); + printf("UnZoom - pad fPad gPad %p %p %p\n",pad,fPad,gPad); + + //pad->cd(); + + pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]); + pad->Modified(); +} + +//_____________________________________________________________________________ +void AliITSdisplay::ResetPoints() +{ + // + // Reset array of points + // + if (fPoints) { + fPoints->Delete(); + delete fPoints; + fPoints = 0; + } +} +//_____________________________________________________________________________ +void AliITSdisplay::ResetPhits() +{ + // + // Reset array of points + // + if (fPhits) { + fPhits->Delete(); + delete fPhits; + fPhits = 0; + } +} +//_____________________________________________________________________________ +void AliITSdisplay::ResetRpoints() +{ + // + // Reset array of points + // + if (fRpoints) { + fRpoints->Delete(); + delete fRpoints; + fRpoints = 0; + } +} +//_____________________________________________________________________________ +void AliITSdisplay::ResetR2points() +{ + // + // Reset array of points + // + if (fR2points) { + fR2points->Delete(); + delete fR2points; + fR2points = 0; + } +} +//_____________________________________________________________________________ +void AliITSdisplay::ResetCpoints() +{ + // + // Reset array of points + // + if (fCpoints) { + fCpoints->Delete(); + delete fCpoints; + fCpoints = 0; + } +} + + + + + + + + + + + diff --git a/ITS/AliITSdisplay.h b/ITS/AliITSdisplay.h new file mode 100644 index 00000000000..4170e9de042 --- /dev/null +++ b/ITS/AliITSdisplay.h @@ -0,0 +1,157 @@ +#ifndef AliITSdisplay_H +#define AliITSdisplay_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +////////////////////////////////////////////////////////////////////////// +// // +// AliDisplay // +// // +// Utility class to display ALice outline, tracks, hits,.. // +// // +////////////////////////////////////////////////////////////////////////// + +//#ifndef ROOT_TObject +#include +//#endif +#include "AliDisplay.h" + +class TCanvas; +class TPad; +class TList; +class TSlider; +class TButton; +class TArc; +class AliITSMapA2; + +const Int_t kMAXZOOM = 20; + +class AliITSdisplay : public AliDisplay { + +private: + Int_t fEvent; + + Int_t fLayer; + Int_t fLadder; + Int_t fDetector; + Int_t fModule; + Int_t fNmodules; + + Float_t fYmodule; + Option_t *fOption; // option for type od det ? + + Int_t fPdgParticle; + Int_t fPdgParent; + + Int_t fZoomMode; //=1 if in zoom mode + + Bool_t fDrawHist; //Flag True if draw histograms + AliITSMapA2 *fMap; + + Bool_t fDrawClusters; //Flag True if Clusters to be drawn + Bool_t fDrawCoG; //Flag True if CoG to be drawn + Bool_t fDrawCathCor; //Flag True if correlated point + //to be drawn + Float_t fTheta; //Viewing angle theta + Float_t fPhi; //Viewing angle phi + Float_t fPsi; //Viewving angle psi (rotation on display) + // Float_t fRzone; // + Float_t fRrange; //Size of view in R + Float_t fZrange; //Size of view along Z + Float_t fZoomX0[20]; //Low x range of zoom number i + Float_t fZoomY0[20]; //Low y range of zoom number i + Float_t fZoomX1[20]; //High x range of zoom number i + Float_t fZoomY1[20]; //High y range of zoom number i + Int_t fZooms; //Number of zooms + + Int_t fHitsCuts; //Number of hits surviving cuts + Int_t fClustersCuts; //Number of clusters surviving cuts + + TCanvas *fCanvas; //Pointer to the display canvas + TPad *fTrigPad; //Pointer to the trigger pad + TPad *fColPad; //Pointer to the colors pad + TPad *fButtons; //Pointer to the buttons pad + TPad *fPad; //Pointer to the event display main pad + TSlider *fRangeSlider; //Range slider + TButton *fPickButton; //Button to activate Pick mode + TButton *fZoomButton; //Button to activate Zoom mode + TArc *fArcButton; //Gren/Red button to show Pick/Zoom mode + TObjArray *fPoints; //Array of points for each cathode + TObjArray *fPhits; //Array of hit points for each chamber + TObjArray *fRpoints; //Array of cog points for each cathode + TObjArray *fR2points; //Array of cog points for each cathode + TObjArray *fCpoints; //Array of correlated points for each first cathode + + +public: + AliITSdisplay(); + AliITSdisplay(Int_t size); + virtual ~AliITSdisplay(); + virtual void Clear(Option_t *option=""); + virtual void CreateModuleCanvas(Int_t size); + virtual void DisplayButtons(); + virtual void CreateColors(); + virtual void DisplayColorScale(); + virtual Int_t DistancetoPrimitive(Int_t px, Int_t py); + virtual void Draw(Option_t *option=""); + virtual void DrawClusters(); + virtual void DrawHits(); + virtual void DrawCoG(); + virtual void DrawCoG2(); + virtual void DrawCathCor(); + + virtual void DrawTitle(Option_t *option=""); + virtual void DrawView(Float_t theta, Float_t phi, Float_t psi=0); + virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py); + Int_t GetZoomMode() {return fZoomMode;} + Int_t GetLayer() {return fLayer;} + Int_t GetLadder() {return fLadder;} + Int_t GetDetector() {return fDetector;} + Int_t GetModule() {return fModule;} + Int_t GetEvent() {return fEvent;} + Float_t GetYmodule() {return fYmodule;} + Bool_t GetDrawHistOpt() {return fDrawHist;} + AliITSMapA2 *GetMap() {return fMap;} + void GetPadCxy(Int_t,Int_t,Float_t *,Float_t *); + void GetPadIxy(Int_t &,Int_t &,Float_t,Float_t); + virtual void LoadDigits(Int_t module); + virtual void LoadHits(Int_t module); + virtual void LoadCoG(Int_t chamber, Int_t cathode); + virtual void LoadCoG2(Int_t chamber, Int_t cathode); + virtual void LoadCathCor(Int_t chamber); + TPad *Pad() {return fPad;} + TObjArray *Points() {return fPoints;} + TObjArray *Phits() {return fPhits;} + TObjArray *Rpoints() {return fRpoints;} + TObjArray *R2points() {return fR2points;} + TObjArray *Cpoints() {return fCpoints;} + virtual void Paint(Option_t *option=""); + virtual void SetModule(Int_t layer=1, Int_t ladder=1, Int_t detector=1); // *MENU* + virtual void SetModuleNumber(Int_t module=393); // *MENU* + virtual void SetParticle(Int_t code=-211) {fPdgParticle=code;}// *MENU* + virtual void SetParent(Int_t code=0) {fPdgParent=code;}// *MENU* + virtual void SetEvent(Int_t newevent=0); // *MENU* + virtual void SetDrawHist(Bool_t draw=kFALSE) {fDrawHist=draw;} // *MENU* + virtual void SetDrawClusters(Bool_t draw=kTRUE) {fDrawClusters=draw;} // *MENU* + virtual void SetDrawCoG(Bool_t draw=kTRUE) {fDrawCoG=draw;} // *MENU* + virtual void SetDrawCathCor(Bool_t draw=kFALSE) {fDrawCathCor=draw;} // *MENU* + virtual void SetRange(Float_t rrange=250., Float_t zrange=1050.); // *MENU* + virtual void SetView(Float_t theta=-90, Float_t phi=90, Float_t psi=180); // *MENU* + virtual void SetPickMode(); + virtual void SetZoomMode(); + virtual void ShowNextEvent(Int_t delta=1); + virtual void UnZoom(); // *MENU* + virtual void DrawHistograms(); + virtual void NextModule(Int_t delta=1); + virtual void ResetPoints(); + virtual void ResetPhits(); + virtual void ResetRpoints(); + virtual void ResetR2points(); + virtual void ResetCpoints(); + + ClassDef(AliITSdisplay, 0) //Utility class to display ITS clusters... +}; + +#endif diff --git a/ITS/AliITSetfSDD.cxx b/ITS/AliITSetfSDD.cxx index 865c62dd720..b28e796cf29 100644 --- a/ITS/AliITSetfSDD.cxx +++ b/ITS/AliITSetfSDD.cxx @@ -13,19 +13,6 @@ * 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 #include #include "AliITSetfSDD.h" @@ -35,70 +22,57 @@ $Id$ // Written by Piergiorgio Cerello // November 23 1999 // -// AliITSmapSDD is the map of SDDs. -// -//Begin_Html -/* - - -
- -

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

-*/
-//End_Htm
-//extern Int_t power(Int_t b, Int_t e);
-
 //_____________________________________________________________________________
 ClassImp(AliITSetfSDD)
 
 Int_t ppower(Int_t b, Int_t e) {
-  Int_t power = 1,i;
-  for(i=0; i= PI) VA -= (2.*PI);
@@ -107,14 +81,14 @@ AliITSetfSDD::AliITSetfSDD(Double_t timeclock)
         }
       }
 
-      if(fPole_M[k]) {
-        Double_t VPR = -fPole_R[k];
-        Double_t VPI = frequency - fPole_I[k];
+      if(fPoleM[k]) {
+        Double_t VPR = -fPoleR[k];
+        Double_t VPI = frequency - fPoleI[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++) {
+        for(j=1; j<= (Int_t) fPoleM[k]; j++) {
           VM /= VPM;
           VA -= VPA;
           if(VA >= PI) VA -= (2.*PI);
@@ -126,64 +100,64 @@ AliITSetfSDD::AliITSetfSDD(Double_t timeclock)
       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;
+      fTfR[i] = VR*ppower(10,9);
+      fTfI[i] = VI*ppower(10,9);
+      //cout << "fTfR[" << i << "] = " << fTfR[i] << endl;
+      //cout << "fTfI[" << i << "] = " << fTfI[i] << endl;
       if(i) {
-        fTf_R[fMaxNofSamples-i] = fTf_R[i];
-        fTf_I[fMaxNofSamples-i] = -fTf_I[i];
+        fTfR[fkMaxNofSamples-i] = fTfR[i];
+        fTfI[fkMaxNofSamples-i] = -fTfI[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);
+  for(i=0; i<=fkMaxNofSamples/2; i++) {
+    fWR[i] = cos(-2.*PI*i/fkMaxNofSamples);
+    fWI[i] = sin(-2.*PI*i/fkMaxNofSamples);
     if(i) {
-      fW_R[fMaxNofSamples-i] = fW_R[i];
-      fW_I[fMaxNofSamples-i] = -fW_I[i];
+      fWR[fkMaxNofSamples-i] = fWR[i];
+      fWI[fkMaxNofSamples-i] = -fWI[i];
     }
   }
 
 }
 
-void AliITSetfSDD::Print()
+void AliITSetfSDD::PrintElectronics()
 {
-  Int_t i;
   cout << "Sampling Time " << fSamplingTime << endl;
-  cout << "Number of Time Samples " << fMaxNofSamples << endl;
+  cout << "Number of Time Samples " << fkMaxNofSamples << 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
-#include 
 #include 
 #include 
+
+
 #include "AliITSgeom.h"
 #include "AliITSgeomSPD300.h"
 #include "AliITSgeomSPD425.h"
@@ -314,9 +309,8 @@ AliITSgeom::~AliITSgeom(){
 ////////////////////////////////////////////////////////////////////////
   // Default destructor.
   // if arrays exist delete them. Then set everything to zero.
-   Int_t i;
    if(fGm!=0){
-      for(i=0;iangles[0] = o;	// Added 25-05-00 S. Vanadia
+      g->angles[1] = p;
+      g->angles[2] = q;
+      g->angles[3] = r;
+      g->angles[4] = s;
+      g->angles[5] = t;
+      //printf("angles from file: %f %f %f %f %f %f\n",o,p,q,r,s,t);
+      //printf("constructor angles: %f %f %f %f %f %f\n", g->angles[0], g->angles[1], g->angles[2], g->angles[3], g->angles[4], g->angles[5]);
+      // end part coming from tracking
+
       oor = byPI*o;
       pr = byPI*p;
       qr = byPI*q;
@@ -399,6 +405,29 @@ AliITSgeom::AliITSgeom(const char *filename){
       sr = byPI*s;
       tr = byPI*t;
 
+      // Tracking rotation matrix 25-5-2000
+      if (l==0) { 
+                  ppr = (Double_t)(p+90.0)*byPI;
+                  rrr = (Double_t)(r+90.0)*byPI; 
+		}
+	   else { 
+	          ppr = (Double_t)(p-90.0)*byPI;
+	          rrr = (Double_t)(r-90.0)*byPI;
+		}
+		 
+
+      g->rottrack[0][0]=TMath::Sin(oor)*TMath::Cos(ppr);
+      g->rottrack[1][0]=TMath::Sin(oor)*TMath::Sin(ppr);
+      g->rottrack[2][0]=TMath::Cos(oor);
+      g->rottrack[0][1]=TMath::Sin(qr)*TMath::Cos(rrr);
+      g->rottrack[1][1]=TMath::Sin(qr)*TMath::Sin(rrr);
+      g->rottrack[2][1]=TMath::Cos(qr);
+      g->rottrack[0][2]=TMath::Sin(sr)*TMath::Cos(tr);
+      g->rottrack[1][2]=TMath::Sin(sr)*TMath::Sin(tr);
+      g->rottrack[2][2]=TMath::Cos(sr);
+      // End tracking rotation matrix
+
+
       g->fx0   = x;
       g->fy0   = y;
       g->fz0   = z;
@@ -516,6 +545,7 @@ AliITSgeom& AliITSgeom::operator=(const AliITSgeom &source){
 // class is then modified by introducing some misalignment.
 ////////////////////////////////////////////////////////////////////////
    Int_t i,j,k;
+   Int_t ii,jj;
 
    if(this == &source) return *this; // don't assign to ones self.
 
@@ -544,12 +574,72 @@ AliITSgeom& AliITSgeom::operator=(const AliITSgeom &source){
 	  fGm[i][j].frx = source.fGm[i][j].frx;
 	  fGm[i][j].fry = source.fGm[i][j].fry;
 	  fGm[i][j].frz = source.fGm[i][j].frz;
+
+	  fGm[i][j].angles[0] = source.fGm[i][j].angles[0];	// Added S.Vanadia
+	  fGm[i][j].angles[1] = source.fGm[i][j].angles[1];
+	  fGm[i][j].angles[2] = source.fGm[i][j].angles[2];
+	  fGm[i][j].angles[3] = source.fGm[i][j].angles[3];
+	  fGm[i][j].angles[4] = source.fGm[i][j].angles[4];
+	  fGm[i][j].angles[5] = source.fGm[i][j].angles[5];
+
 	  for(k=0;k<9;k++) fGm[i][j].fr[k] = source.fGm[i][j].fr[k];
+	  for (ii=0;ii<3;ii++)					// Added S. Vanadia
+	     for (jj=0;jj<3;jj++)
+	         fGm[i][j].rottrack[ii][jj] = source.fGm[i][j].rottrack[ii][jj];
       } // end for j
    } // end for i
    return *this;
 }
 //________________________________________________________________________
+void AliITSgeom::GtoLtracking(Int_t lay,Int_t lad,Int_t det,
+                              const Double_t *g,Double_t *l){
+////////////////////////////////////////////////////////////////////////
+// Added by S. Vanadia 25-5-2000
+////////////////////////////////////////////////////////////////////////
+   Double_t x,y,z;
+   AliITSgeomS *gl;
+   
+   lay--;lad--;det--;  
+   
+   gl = &(fGm[lay][fNdet[lay]*lad+det]);
+	
+   x    = g[0] - gl->fx0;
+   y    = g[1] - gl->fy0;
+   z    = g[2] - gl->fz0;
+   
+   l[0] = gl->rottrack[0][0]*x + gl->rottrack[1][0]*y + gl->rottrack[2][0]*z;
+   l[1] = gl->rottrack[0][1]*x + gl->rottrack[1][1]*y + gl->rottrack[2][1]*z;
+   l[2] = gl->rottrack[0][2]*x + gl->rottrack[1][2]*y + gl->rottrack[2][2]*z;
+	
+   return;
+}
+//________________________________________________________________________
+void AliITSgeom::LtoGtracking(Int_t lay,Int_t lad,Int_t det,
+                              const Double_t *l,Double_t *g){
+////////////////////////////////////////////////////////////////////////
+// Added by S. Vanadia 25-5-2000
+////////////////////////////////////////////////////////////////////////
+
+   Double_t xx,yy,zz;
+   AliITSgeomS *gl;
+   
+   lay--;lad--;det--;  
+   
+   gl = &(fGm[lay][fNdet[lay]*lad+det]);
+  
+   xx    = gl->rottrack[0][0]*l[0] + gl->rottrack[0][1]*l[1] + gl->rottrack[0][2]*l[2];
+   yy    = gl->rottrack[1][0]*l[0] + gl->rottrack[1][1]*l[1] + gl->rottrack[1][2]*l[2];
+   zz    = gl->rottrack[2][0]*l[0] + gl->rottrack[2][1]*l[1] + gl->rottrack[2][2]*l[2];
+
+
+   g[0] = xx + gl->fx0;
+   g[1] = yy + gl->fy0;
+   g[2] = zz + gl->fz0;
+      
+
+   return;
+}
+//________________________________________________________________________
 void AliITSgeom::GtoL(Int_t lay,Int_t lad,Int_t det,
                        const Double_t *g,Double_t *l){
 ////////////////////////////////////////////////////////////////////////
@@ -1274,6 +1364,7 @@ ofstream & AliITSgeom::PrintGeom(ofstream &lRb){
 ////////////////////////////////////////////////////////////////////////
    // Stream an object of class AliITSgeom.
     Int_t i,j,k;
+    Int_t ii, jj;
 
     lRb.setf(ios::scientific);
     lRb << fNlayers << " ";
@@ -1287,8 +1378,17 @@ ofstream & AliITSgeom::PrintGeom(ofstream &lRb){
 	lRb <> fNlayers;
       if(fNlad!=0) delete[] fNlad;
@@ -1328,7 +1429,16 @@ ifstream & AliITSgeom::ReadGeom(ifstream &lRb){
 	      lRb >> fGm[i][j].frx;
 	      lRb >> fGm[i][j].fry;
 	      lRb >> fGm[i][j].frz;
+	      lRb >> fGm[i][j].angles[0];
+	      lRb >> fGm[i][j].angles[1];
+	      lRb >> fGm[i][j].angles[2];
+	      lRb >> fGm[i][j].angles[3];
+	      lRb >> fGm[i][j].angles[4];
+	      lRb >> fGm[i][j].angles[5];
 	      for(k=0;k<9;k++) lRb >> fGm[i][j].fr[k];
+	      for (ii=0;ii<3;ii++)					// Added S. Vanadia
+		for (jj=0;jj<3;jj++)
+		  lRb >> fGm[i][j].rottrack[ii][jj];
 	  } // end for j
       } // end for i
 //      lRb >> fShape;
@@ -1692,28 +1802,29 @@ void AliITSgeom::Streamer(TBuffer &lRb){
 ////////////////////////////////////////////////////////////////////////
    // Stream an object of class AliITSgeom.
     Int_t i,j,k,n;
+    Int_t ii,jj;
 
 
-    //   printf("AliITSgeomStreamer starting\n");
+    //printf("AliITSgeomStreamer starting\n");
    if (lRb.IsReading()) {
       Version_t lRv = lRb.ReadVersion(); if (lRv) { }
       TObject::Streamer(lRb);
-//      printf("AliITSgeomStreamer reading fNlayers\n");
+      //printf("AliITSgeomStreamer reading fNlayers\n");
       lRb >> fNlayers;
       if(fNlad!=0) delete[] fNlad;
       if(fNdet!=0) delete[] fNdet;
       fNlad = new Int_t[fNlayers];
       fNdet = new Int_t[fNlayers];
-//      printf("AliITSgeomStreamer fNlad\n");
+      //printf("AliITSgeomStreamer fNlad\n");
       for(i=0;i> fNlad[i];
-//      printf("AliITSgeomStreamer fNdet\n");
+      //printf("AliITSgeomStreamer fNdet\n");
       for(i=0;i> fNdet[i];
       if(fGm!=0){
 	  for(i=0;i> fGm[i][j].frx;
 	      lRb >> fGm[i][j].fry;
 	      lRb >> fGm[i][j].frz;
+	      lRb >> fGm[i][j].angles[0];
+	      lRb >> fGm[i][j].angles[1];
+	      lRb >> fGm[i][j].angles[2];
+	      lRb >> fGm[i][j].angles[3];
+	      lRb >> fGm[i][j].angles[4];
+	      lRb >> fGm[i][j].angles[5];
 	      for(k=0;k<9;k++) lRb >> fGm[i][j].fr[k];
+	      for (ii=0;ii<3;ii++)		      // Added S. Vanadia
+	         for (jj=0;jj<3;jj++)
+	             lRb >> fGm[i][j].rottrack[ii][jj];
 	  } // end for j
       } // end for i
       /*
@@ -1750,10 +1870,19 @@ void AliITSgeom::Streamer(TBuffer &lRb){
 	  lRb << fGm[i][j].frx;
 	  lRb << fGm[i][j].fry;
 	  lRb << fGm[i][j].frz;
+	  lRb << fGm[i][j].angles[0];
+	  lRb << fGm[i][j].angles[1];
+	  lRb << fGm[i][j].angles[2];
+	  lRb << fGm[i][j].angles[3];
+	  lRb << fGm[i][j].angles[4];
+	  lRb << fGm[i][j].angles[5];
 	  for(k=0;k<9;k++) lRb << fGm[i][j].fr[k];
+	  for (ii=0;ii<3;ii++)					// Added S. Vanadia
+	     for (jj=0;jj<3;jj++)
+	         lRb << fGm[i][j].rottrack[ii][jj];
       } // end for i,j
       // lRb << fShape;
       //if (fShape) fShape->Streamer(lRb);
    } // end if reading
-   //   printf("AliITSgeomStreamer Finished\n");
+   //printf("AliITSgeomStreamer Finished\n");
 }
diff --git a/ITS/AliITSgeom.h b/ITS/AliITSgeom.h
index 6456bb12e25..77a2f81cd32 100644
--- a/ITS/AliITSgeom.h
+++ b/ITS/AliITSgeom.h
@@ -18,7 +18,9 @@
 // a specialized structure for ease of implementation.
 /////////////////////////////////////////////////////////////////////////
 #include 
-#include "TObjArray.h"
+#include 
+#include 
+
 #include "AliITSgeomSPD.h"
 #include "AliITSgeomSDD.h"
 #include "AliITSgeomSSD.h"
@@ -29,6 +31,8 @@ struct AliITSgeomS {
     Float_t fx0,fy0,fz0; // Translation vector
     Float_t frx,fry,frz; // Rotation about axis, angle radians
     Float_t fr[9];       // the rotation matrix
+    Float_t angles[6];   // module center, theta and phi
+    Double_t rottrack[3][3]; // the tracking rotation matrix
 };
 
 //_______________________________________________________________________
@@ -137,6 +141,21 @@ class AliITSgeom : public TObject {
     // global coordinate system to the local coordinate system used to do
     // tracking.
 
+    void GtoLtracking(Int_t lay,Int_t lad,Int_t det,const Double_t *g,Double_t *l);
+    void LtoGtracking(Int_t lay,Int_t lad,Int_t det,const Double_t *l,Double_t *g);
+    void GetCenterThetaPhi(Int_t lay,Int_t lad,Int_t det, TVector &x) const {
+                       x(0) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].fx0;
+		       x(1) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].fy0;
+		       x(2) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].fz0;	                         		 
+		       x(3) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].angles[0];
+		       x(4) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].angles[1];
+		       x(5) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].angles[2];
+		       x(6) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].angles[3];
+		       x(7) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].angles[4];
+		       x(8) = fGm[lay-1][fNdet[lay-1]*(lad-1)+det-1].angles[5];
+
+}
+
  private:
     Int_t        fNlayers; // The number of layers.
     Int_t        *fNlad;   // Array of the number of ladders/layer(layer)
diff --git a/ITS/AliITSgeomSDD.cxx b/ITS/AliITSgeomSDD.cxx
index 8c41da6e5b0..84272279d40 100644
--- a/ITS/AliITSgeomSDD.cxx
+++ b/ITS/AliITSgeomSDD.cxx
@@ -15,9 +15,6 @@
 
 /*
 $Log$
-Revision 1.2.4.6  2000/06/11 20:29:39  barbera
-Minore changes.
-
 Revision 1.2.4.2  2000/03/04 23:55:35  nilsen
 Fixed up comments/documentation.
 
diff --git a/ITS/AliITSgeomSDD.h b/ITS/AliITSgeomSDD.h
index 1c2e001021c..ad250006d6a 100644
--- a/ITS/AliITSgeomSDD.h
+++ b/ITS/AliITSgeomSDD.h
@@ -7,9 +7,9 @@
 
 #include 
 #include "TBRIK.h"
-#include "AliITSgeom.h"
+//#include "AliITSgeom.h"
 
-// temporary 
+class AliITSgeom;
 
 class AliITSgeomSDD: public TObject {
  public:
diff --git a/ITS/AliITSgeomSPD.cxx b/ITS/AliITSgeomSPD.cxx
index a920d9d37a6..f919a62deaf 100644
--- a/ITS/AliITSgeomSPD.cxx
+++ b/ITS/AliITSgeomSPD.cxx
@@ -15,9 +15,6 @@
 
 /*
 $Log$
-Revision 1.2.4.5  2000/06/11 20:30:05  barbera
-Minore changes.
-
 Revision 1.3  2000/03/07 18:46:59  nilsen
 Merged form ITS-working to HEAD. Minor changes
 
diff --git a/ITS/AliITSgeomSPD300.cxx b/ITS/AliITSgeomSPD300.cxx
index 19fc1f53d38..547f4243f26 100644
--- a/ITS/AliITSgeomSPD300.cxx
+++ b/ITS/AliITSgeomSPD300.cxx
@@ -15,12 +15,6 @@
 
 /*
 $Log$
-Revision 1.1.2.6  2000/06/12 18:10:03  barbera
-fixed posible compilation errors on HP unix
-
-Revision 1.1.2.5  2000/06/11 20:30:36  barbera
-Minore changes.
-
 Revision 1.4  2000/06/10 20:34:37  nilsen
 Fixed compilation warning with HP unix.
 
diff --git a/ITS/AliITSgeomSPD425.cxx b/ITS/AliITSgeomSPD425.cxx
index 207ba8479cc..d74cfd492fe 100644
--- a/ITS/AliITSgeomSPD425.cxx
+++ b/ITS/AliITSgeomSPD425.cxx
@@ -15,12 +15,6 @@
 
 /*
 $Log$
-Revision 1.1.2.6  2000/06/12 18:10:18  barbera
-fixed posible compilation errors on HP unix
-
-Revision 1.1.2.5  2000/06/11 20:30:56  barbera
-Minore changes.
-
 Revision 1.4  2000/06/10 20:34:22  nilsen
 Fixed compilation warning with HP unix.
 
diff --git a/ITS/AliITSgeomSSD.cxx b/ITS/AliITSgeomSSD.cxx
index 77b4c0d3034..30eaa0fab8a 100644
--- a/ITS/AliITSgeomSSD.cxx
+++ b/ITS/AliITSgeomSSD.cxx
@@ -15,9 +15,6 @@
 
 /*
 $Log$
-Revision 1.2.4.6  2000/06/11 20:30:21  barbera
-Minore changes.
-
 Revision 1.2.4.2  2000/03/04 23:55:59  nilsen
 Fixed up the comments/documentation
 
diff --git a/ITS/AliITSgeomSSD.h b/ITS/AliITSgeomSSD.h
index 2b736b23376..3e0a2614992 100644
--- a/ITS/AliITSgeomSSD.h
+++ b/ITS/AliITSgeomSSD.h
@@ -7,8 +7,10 @@
 
 #include 
 #include "TBRIK.h"
-#include "AliITSgeom.h"
-// temporarily - to be able to compile the code
+//#include "AliITSgeom.h"
+
+
+class AliITSgeom;
 
 class AliITSgeomSSD: public TObject {
 
diff --git a/ITS/AliITShit.cxx b/ITS/AliITShit.cxx
index 45a430a294b..342991acd36 100644
--- a/ITS/AliITShit.cxx
+++ b/ITS/AliITShit.cxx
@@ -15,9 +15,6 @@
 
 /*
 $Log$
-Revision 1.3.4.4  2000/06/11 20:31:37  barbera
-Coding conventions update.
-
 Revision 1.3.4.2  2000/03/04 23:43:57  nilsen
 Fixed up the comments/documentation.
 
diff --git a/ITS/AliITShit.h b/ITS/AliITShit.h
index 51a6423904b..16c74917408 100644
--- a/ITS/AliITShit.h
+++ b/ITS/AliITShit.h
@@ -8,7 +8,6 @@
 #include "AliDetector.h"
 #include "TParticle.h"
 #include "AliHit.h" 
-#include "AliDigit.h"
 #include "AliITSgeom.h"
 
 
diff --git a/ITS/AliITSmodule.cxx b/ITS/AliITSmodule.cxx
index 057851be929..3891594f1f6 100644
--- a/ITS/AliITSmodule.cxx
+++ b/ITS/AliITSmodule.cxx
@@ -15,15 +15,6 @@
 
 /*
 $Log$
-Revision 1.4  2000/06/12 23:49:02  nilsen
-New ITS code replacing the old structure and simulations code.
-
-Revision 1.3.4.4  2000/06/12 18:10:32  barbera
-fixed posible compilation errors on HP unix
-
-Revision 1.3.4.3  2000/06/11 20:34:20  barbera
-Update class for the new structures.
-
 Revision 1.3.4.2  2000/03/02 21:42:29  nilsen 
 Linked AliDetector::fDigit to AliITSmodule::fDigitsM and AliITS::fITSRecPoints
 to AliITSmodule::fRecPointsM. Renamed AliITSmodule::fPointsM to fRecPointsM.
@@ -46,11 +37,9 @@ Introduction of the Copyright and cvs Log
 
 */
 
-#include "AliITSmodule.h"
 
 #include "AliRun.h"
 #include "AliITS.h"
-#include "AliITShit.h"
 
 ClassImp(AliITSmodule)
 
@@ -92,9 +81,8 @@ AliITSmodule::~AliITSmodule() {
     // we must first destroy all of it's members.
 
     fIndex   = 0;
-    Int_t i;
     if(fHitsM){
-	for(i=0;iGetEntriesFast();i++) 
+	for(Int_t i=0;iGetEntriesFast();i++) 
 	    delete ((AliITShit *)(fHitsM->At(i)));
 	// must delete each object in the TObjArray.
 	delete fHitsM;
@@ -119,7 +107,7 @@ AliITSmodule& AliITSmodule::operator=(const AliITSmodule &source){
 ////////////////////////////////////////////////////////////////////////
   printf("AliITSmodule error: AliITSmodule class has not to be copied! Exit.\n");
   exit(1);
-  return *this;
+  return *this; // fake return neded on Sun
 } 
 
 //_________________________________________________________________________
@@ -129,19 +117,18 @@ AliITSmodule& AliITSmodule::operator=(const AliITSmodule &source){
 Int_t AliITSmodule::AddHit(AliITShit* hit,Int_t t,Int_t h) {
 // Hits management
 
-    Int_t i;
     fHitsM->AddLast(new AliITShit(*hit));
     Int_t fNhitsM = fHitsM->GetEntriesFast();
     if(fNhitsM-1>=fTrackIndex->GetSize()){ // need to expand the TArrayI
 	TArrayI *p = new TArrayI(fNhitsM+64);
-	for(i=0;iGetSize();i++) 
+	for(Int_t i=0;iGetSize();i++) 
 	    (*p)[i] = fTrackIndex->At(i);
 	delete fTrackIndex;
 	fTrackIndex = p;
     } // end if
     if(fNhitsM-1>=fHitIndex->GetSize()){ // need to expand the TArrayI
 	TArrayI *p = new TArrayI(fNhitsM+64);
-	for(i=0;iGetSize();i++) 
+	for(Int_t i=0;iGetSize();i++) 
 	    (*p)[i] = fHitIndex->At(i);
 	delete fHitIndex;
 	fHitIndex = p;
diff --git a/ITS/AliITSpackageSSD.cxx b/ITS/AliITSpackageSSD.cxx
index 5c36f8f2c3c..e2214e8b6a7 100644
--- a/ITS/AliITSpackageSSD.cxx
+++ b/ITS/AliITSpackageSSD.cxx
@@ -1,4 +1,8 @@
+#include 
+#include 
+
 #include "AliITSpackageSSD.h"
+
 //************************************************
 //Piotr Krzysztof Skowronski
 //Warsaw University of Technology
@@ -75,12 +79,12 @@ AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
   fNclustersN= package.fNclustersN;
   fNclustersP= package.fNclustersP;
   
-  for(i =0; iGetCrossNo();
   
-  for(i =0;iGetCross(i);
     ((AliITSclusterSSD *)((*fClustersN)[idx])   )->DelCross(clToDelIdx);
    }
  
  
- for(i=index;iGetCrossNo())==0) DelNCluster(i);
   }
@@ -285,21 +289,21 @@ void AliITSpackageSSD::DelNCluster(Int_t index)
   AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
   Int_t ncr = clToDel->GetCrossNo();
   
-  for(i =0;iGetCross(i);
     ((AliITSclusterSSD *)((*fClustersP)[idx])   )->DelCross(clToDelIdx);
    }
  
  
- for(i=index;iGetCrossNo())==0) DelPCluster(i);
   }
@@ -329,7 +333,7 @@ void AliITSpackageSSD::DelPClusterOI(Int_t index)
     }
    else
     {
-     for(i=1;iGetCrossNo();  //number of crosses for this cluster
  Int_t indcro;                 //index of given cluster on side N that 
                                // this cluster crosses with
    
- // printf("NC %d \n",NC);
-
-
  if (np == fNclustersP-1) {
-   //printf("if \n");
-   for(i=0;iGetCross(i);
-     //printf("if: i indcro %d %d\n",i, indcro);
      if(IsFree(indcro,np,occup)) {
         occup[np]=indcro;
-	//printf("if- isFree: i np occup[np] %d %d %d\n",i,np,occup[np]);
         for(j=0;jGetCross(i);
-       //printf("else: i indcro %d %d\n",i, indcro);
        if(IsFree(indcro,np,occup)) {
       	  occup[np]=indcro;
-	  //printf("else:recursive call - i np occup %d %d %d\n",i,np,occup[np]);
 	  if (nuGetCrossNo();j++)
+   for (j=0;jGetCrossNo();j++)
     {
       cout<GetCross(j)<<" ";
     }
@@ -525,10 +509,10 @@ for(i=0;iGetCrossNo();j++)
+   for (j=0;jGetCrossNo();j++)
     {
       cout<GetCross(j)<<" ";
     }
@@ -563,8 +547,7 @@ 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
+*/
+//End_Html
+//                                                                           //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "AliRun.h"
+#include "AliITSpoints.h"
+#include "AliITSdisplay.h"
+#include "AliITSMap.h"
+#include "AliITSRecPointSDDnew.h"
+
+
+//const Int_t MAXNipx=1026, MAXNipy=1026;
+const Int_t MAXNipx=752, MAXNipy=256;
+
+static AliITSMapA2 *sMap = 0; 
+static Int_t  sModule=0; 
+ 
+ClassImp(AliITSpoints)
+
+//_____________________________________________________________________________
+AliITSpoints::AliITSpoints()
+{
+  //
+  // Default constructor
+  //
+  fModuleIndex = -1;
+  fHitIndex = -1;
+  fTrackIndex = -1;
+  fDigitIndex = -1;
+  fMarker[0] = fMarker[1] = fMarker[2]=0;
+  fMatrix = 0;
+
+  //fConnect=kFALSE;
+}
+
+//_____________________________________________________________________________
+AliITSpoints::AliITSpoints(Int_t npoints)
+  :AliPoints(npoints)
+{
+  //
+  // Standard constructor
+  //
+  fModuleIndex = -1;
+  fHitIndex = -1;
+  fTrackIndex = -1;
+  fDigitIndex = -1;
+  fMarker[0] = fMarker[1] = fMarker[2]=0;
+  fMatrix = 0;
+
+  //fConnect=kFALSE;
+
+}
+	 
+//_____________________________________________________________________________
+AliITSpoints::~AliITSpoints()
+{
+  //
+  // Default destructor
+  //
+  fHitIndex = 0;
+  fTrackIndex = 0;
+  fDigitIndex = 0;
+  fModuleIndex = 0;
+  for (Int_t i=0;i<3;i++){
+      if (fMarker[i]) delete fMarker[i];
+  }
+  fMatrix = 0;
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::ExecuteEvent(Int_t event, Int_t px, Int_t py)
+{
+  //
+  //*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*-*-*-*-*
+  //*-*                =========================================
+  //*-*
+  //*-*  This member function must be implemented to realize the action
+  //*-*  corresponding to the mouse click on the object in the window
+  //*-*
+  //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+
+  if (!gPad) return;
+
+  gPad->SetCursor(kCross);
+
+  TObject *select = gPad->GetSelected();
+  if(!select) {printf("no select \n"); return;}
+  if (!select->InheritsFrom("AliITSpoints")) {gPad->SetUniqueID(0); return;}
+
+   //erase old position and draw a line at current position
+   switch (event) {
+
+
+   case kButton1Down:
+        return;
+   case kButton1Motion:
+       AnodeProjection(px,py);
+       return;
+   case kButton1Up:
+       return;
+
+
+   case kButton1Double:
+       TimeProjection(px,py);
+       return;
+
+       /* why button2 does not work ?
+        it does not know kButton2Down, kButton2Motion, kButton2Up
+   case kButton2Down:
+       printf("Button2Down \n");
+       return;
+   case kButton2Motion:
+       printf("Button2Motion \n");
+       TimeProjection(px,py);
+       return;
+   case kButton2Up:
+       return;
+   */
+   }
+   
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::AnodeProjection(Int_t px, Int_t py) 
+{
+  //if(!fDrawHist) return;
+
+    gPad->SetCursor(kMove);
+    gPad->GetCanvas()->FeedbackMode(kTRUE);
+
+   Float_t xmin = gPad->GetX1();
+   Float_t xmax = gPad->GetX2();
+   Float_t ymin = gPad->GetY1();
+   Float_t ymax = gPad->GetY2();
+   //printf("xmin,xmax,ymin,ymax %f %f %f %f\n",xmin,xmax,ymin,ymax);
+    Float_t x,y;
+   // x,y in the -1,1 scale
+    x = gPad->AbsPixeltoX(px);
+    y = gPad->AbsPixeltoY(py);
+
+    Float_t scale[3],center[3];
+    Int_t irep;
+    gPad->GetView()->FindScope(scale,center,irep);
+
+    AliITSdisplay* display=((AliITSdisplay*)(gAlice->Display()));
+     Int_t anode, timebin;
+    display->GetPadIxy(anode,timebin,x*scale[0],y*scale[0]);
+    
+    Int_t amin, amax, tmin, tmax;
+    display->GetPadIxy(amin,tmin,xmin*scale[0],ymin*scale[0]);
+    display->GetPadIxy(amax,tmax,xmax*scale[0],ymax*scale[0]);
+
+    if (xmin < 0 && xmax > 0) {
+       if (0-xmin > xmax) amax-=374;
+       else {amin+=374; tmin=tmax;}
+       tmax=256;
+    } 
+    Int_t tminold=tmin;
+    Int_t tmaxold=tmax;
+    tmin=TMath::Min(tminold,tmaxold);
+    tmax=TMath::Max(tminold,tmaxold);
+
+    Int_t nbiny = tmax-tmin;
+
+    //printf("amin amax tmin tmax anode, timebin %d %d %d %d %d %d\n",amin,amax,tmin,tmax,anode,timebin);
+
+    //create or set the new canvas c2
+   TVirtualPad *padsav = gPad;
+   //printf("AnodeProj: gPad %p\n",gPad);
+   TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
+   if(c2) delete c2->GetPrimitive("Anode Projection");
+   if(c2) delete c2->GetPrimitive("Time Projection");
+   else     c2=new TCanvas("c2");
+   c2->cd();
+   c2->SetFillColor(0);
+
+   char title[30];
+   sprintf(title,"anode=%d",anode);
+
+   TH1F *h1=new TH1F("Anode Projection","",nbiny,(float)tmin,(float)tmax);
+
+   h1->SetTitle(title);
+   h1->SetTitleSize(2.);
+   h1->SetTitleOffset(2.);
+   h1->SetLabelSize(0.05);
+   h1->SetYTitle(title);
+   //h1->SetStats(0);
+
+   AliITSMapA2 *sMap=display->GetMap();
+
+   for (int j=tmin;jGetSignal(anode-1,j-1));
+      h1->Fill((float)j,(float)sMap->GetSignal(anode-1,j-1));
+   }
+   h1->Smooth(1);
+   h1->Fit("gaus","ql");
+   h1->Draw();
+
+   c2->Update();
+   padsav->cd();
+   //printf("AnodeProj: gPad padsav %p %p\n",gPad,padsav);
+
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::TimeProjection(Int_t px, Int_t py)
+{
+  //if(!fDrawHist) return;
+  //printf("TimeProjection \n");
+
+    gPad->SetCursor(kRightSide);
+    gPad->GetCanvas()->FeedbackMode(kTRUE);
+
+   Float_t xmin = gPad->GetX1();
+   Float_t xmax = gPad->GetX2();
+   Float_t ymin = gPad->GetY1();
+   Float_t ymax = gPad->GetY2();
+   //printf("xmin,xmax,ymin,ymax %f %f %f %f\n",xmin,xmax,ymin,ymax);
+    Float_t x,y;
+   // x,y in the -1,1 scale
+    x = gPad->AbsPixeltoX(px);
+    y = gPad->AbsPixeltoY(py);
+
+    Float_t scale[3],center[3];
+    Int_t irep;
+    gPad->GetView()->FindScope(scale,center,irep);
+
+    AliITSdisplay* display=((AliITSdisplay*)(gAlice->Display()));
+     Int_t anode, timebin;
+    display->GetPadIxy(anode,timebin,x*scale[0],y*scale[2]);
+    
+    Int_t amin, amax, tmin, tmax;
+    display->GetPadIxy(amin,tmin,xmin*scale[0],ymin*scale[2]);
+    display->GetPadIxy(amax,tmax,xmax*scale[0],ymax*scale[2]);
+
+    if (xmin < 0 && xmax > 0) {
+       if (0-xmin > xmax) amax-=374;
+       else {amin+=374;tmin=tmax;}
+       tmax=256;
+    } 
+
+    Int_t aminold=amin;
+    Int_t amaxold=amax;
+    amin=TMath::Min(aminold,amaxold);
+    amax=TMath::Max(aminold,amaxold);
+
+    Int_t nbinx = amax-amin;
+
+    //printf("amin amax tmin tmax anode, timebin %d %d %d %d %d %d\n",amin,amax,tmin,tmax,anode,timebin);
+
+    //create or set the new canvas c2
+   TVirtualPad *padsav = gPad;
+   TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
+   if(c2) delete c2->GetPrimitive("Anode Projection");
+   if(c2) delete c2->GetPrimitive("Time Projection");
+   else     c2=new TCanvas("c2");
+   c2->cd();
+   c2->SetFillColor(0);
+
+   char title[30];
+   //printf("title: anode, timebin %d %d\n",anode,timebin);
+   sprintf(title,"time sample=%d",timebin);
+
+   TH1F *h2=new TH1F("Time Projection","",nbinx,(float)amin,(float)amax);
+
+   h2->SetTitle(title);
+   h2->SetTitleSize(2.);
+   h2->SetTitleOffset(2.);
+   h2->SetLabelSize(0.05);
+   h2->SetYTitle(title);
+   //h2->SetStats(0);
+
+   AliITSMapA2 *sMap=display->GetMap();
+
+   for (int i=amin;iGetSignal(i-1,timebin-1));
+      h2->Fill((float)i,(float)sMap->GetSignal(i-1,timebin-1));
+   }
+   h2->Smooth(1);
+   h2->Fit("gaus","ql");
+   h2->Draw();
+
+   c2->Update();
+   padsav->cd();
+
+}
+//_____________________________________________________________________________
+void AliITSpoints::DisplayModule()
+{
+  /*
+ 
+   if (!((AliITSDisplay*)(gAlice->Display()))->GetDrawTracksOpt()) return;
+   // ????
+   ((AliITSDisplay*)(gAlice->Display()))->SetModuleNumber(fModuleIndex);
+   Int_t event=((AliITSDisplay*)(gAlice->Display()))->GetEvent();
+   ((AliITSDisplay*)(gAlice->Display()))->SetEvent(event);
+   ((AliITSDisplay*)(gAlice->Display()))->SetRange(4,4);
+   //((AliITSDisplay*)(gAlice->Display()))->DrawModule(fModuleIndex);
+  */
+}
+
+//_____________________________________________________________________________
+const Text_t *AliITSpoints::GetName() const
+{
+  //
+  // Return name of the Geant3 particle corresponding to this point
+  //
+  TParticle *particle = GetParticle();
+  if (particle) return particle->GetName();
+  else  return IsA()->GetName();
+  //if (!particle) return "Particle";
+}
+
+//_____________________________________________________________________________
+Text_t *AliITSpoints::GetObjectInfo(Int_t px, Int_t py)
+{
+  //
+  //   Redefines TObject::GetObjectInfo.
+  //   Displays the info (particle,etc
+  //   corresponding to cursor position px,py
+  //
+   if (!gPad) return (char*)"";
+  static char info[64];
+  char an[6], tbin[9], track[6];
+  an="Anode"; tbin="Time bin"; track="Track"; 
+  if(strcmp(GetName(),"AliITSpoints ")) {
+        AliITSdigitSDD *dig=GetDigit();
+        if (!dig) {sprintf(info,"%s %s %d",GetName(),track,fIndex); return info;} 
+        int anode=dig->fCellX;
+        int time=dig->fCellY;
+        sprintf(info,"%s %d %s %d %s %d",an,anode+1,tbin,time+1,track,fIndex);
+  } else {
+        if(strcmp(GetName(),"TView ")) {
+            Float_t x = gPad->AbsPixeltoX(px);
+            Float_t y = gPad->AbsPixeltoY(py);
+            sprintf(info,"%s x=%.3g, y=%.3g",GetName(),gPad->PadtoX(x),gPad->PadtoY(y));
+	} else {
+            sprintf(info,"%s %s %d",GetName(),track,fIndex); 
+	}
+
+  }
+
+  return info;
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::DumpHit()
+{
+  //
+  //   Dump hit corresponding to this point
+  //
+  AliITShit *hit = GetHit();
+  if (hit) hit->Dump();
+
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::DumpDigit()
+{
+  //
+  //   Dump digit corresponding to this point
+  //
+  AliITSdigitSDD *digit = GetDigit();
+  if (digit) digit->Dump();
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::InspectHit()
+{
+  //
+  //   Inspect hit corresponding to this point
+  //
+
+  if (fHitIndex < 0 ) return;
+  TVirtualPad *padsav = gPad;
+  AliITShit *hit = GetHit();
+  if (hit) hit->Inspect();
+  TVirtualPad *padinspect = (TVirtualPad*)(gROOT->GetListOfCanvases())->FindObject("inspect");
+   padinspect->cd();
+   Float_t xmin = gPad->GetX1();
+   Float_t xmax = gPad->GetX2();
+   Float_t ymin = gPad->GetY1();
+   Float_t ymax = gPad->GetY2();
+   Float_t dy   = ymax-ymin;
+
+      TPaveText *pad = new TPaveText(xmin, ymin+0.1*dy, xmax, ymin+0.15*dy);
+      pad->SetBit(kCanDelete);
+      pad->SetFillColor(42);
+      pad->Draw();
+      char ptitle[100];
+      sprintf(ptitle," %s , fTrack: %d  fTrackIndex: %d ",GetName(),fIndex,fTrackIndex);
+      pad->AddText(ptitle);
+      padinspect->cd();
+      padinspect->Update();
+  if (padsav) padsav->cd();
+
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::InspectDigit()
+{
+  //
+  //   Inspect digit corresponding to this point
+  //
+
+  if (fDigitIndex < 0) return;
+  TVirtualPad *padsav = gPad;
+  AliITSdigitSDD *digit = GetDigit();
+  if (digit) digit->Inspect();
+  TVirtualPad *padinspect = (TVirtualPad*)(gROOT->GetListOfCanvases())->FindObject("inspect");
+   padinspect->cd();
+   Float_t xmin = gPad->GetX1();
+   Float_t xmax = gPad->GetX2();
+   Float_t ymin = gPad->GetY1();
+   Float_t ymax = gPad->GetY2();
+   Float_t dy   = ymax-ymin;
+
+      TPaveText *pad = new TPaveText(xmin, ymin+0.1*dy, xmax, ymin+0.25*dy);
+      pad->SetBit(kCanDelete);
+      pad->SetFillColor(42);
+      pad->Draw();
+      char ptitle[11][100];
+      //      sprintf(ptitle[11],"Tracks making this digit");
+      //      pad->AddText(ptitle[11]);
+  for (int i=0;i<3;i++) {
+      if (digit->fTracks[i] == 0) continue;  
+      sprintf(ptitle[i],"fTrackIndex: %d  Charge: %f",digit->fTracks[i],digit->fTcharges[i]);
+      pad->AddText(ptitle[i]);
+  }
+      padinspect->cd();
+      padinspect->Update();
+  if (padsav) padsav->cd();
+    
+}
+
+//_____________________________________________________________________________
+Int_t AliITSpoints::GetTrackIndex()
+{
+  //
+  //   Dump digit corresponding to this point
+  //
+
+  this->Inspect();
+  /*
+  if (fDigitIndex != 0) {
+    Int_t ncol=this->fMatrix->GetNcols();
+    for (int i=0;ifMatrix))(0,i),(*(this->fMatrix))(1,i));
+    }
+  }
+  */
+  return fTrackIndex;
+}
+
+//_____________________________________________________________________________
+AliITShit *AliITSpoints::GetHit() const
+{
+  //
+  //   Returns pointer to hit index in AliRun::fParticles
+  //
+  AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
+  gAlice->TreeH()->GetEvent(fTrackIndex);
+  TClonesArray *ITShits  = ITS->Hits();
+  Int_t nhits = ITShits->GetEntriesFast();
+  if (fHitIndex < 0 || fHitIndex >= nhits) return 0;
+  return (AliITShit*)ITShits->UncheckedAt(fHitIndex);
+}
+
+//_____________________________________________________________________________
+AliITSdigitSDD *AliITSpoints::GetDigit() const
+{
+  //
+  //   Returns pointer to digit index in AliRun::fParticles
+  //
+
+  AliITSdisplay *display=(AliITSdisplay*)gAlice->Display();
+  Int_t module=display->GetModule();
+  Int_t layer=display->GetLayer();
+  Int_t id=(Int_t)((layer-1)/2);
+   
+  AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
+  TClonesArray *ITSdigits  = ITS->DigitsAddress(id);
+  gAlice->TreeD()->GetEvent(module);
+  Int_t ndigits = ITSdigits->GetEntriesFast();
+  if (fDigitIndex < 0 || fDigitIndex >= ndigits) return 0;
+  return (AliITSdigitSDD*)ITSdigits->UncheckedAt(fDigitIndex);
+
+  /*
+  // have smth like ??
+  AliITSgeom *geom  = ITS->GetITSgeom;
+  Int_t lastSPD=geom->GetLastSPD();
+  Int_t lastSDD=geom->GetLastSDD();
+
+  Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
+  if (nent < lastSDD) {
+       // take the appropriate action ...using lastSPD, lastSDD ...
+       // or better introduce an Option_t in the display : All, SPD, SDD, SSD
+       // or combination
+       printf("Digitisation wasn't done for all det types !\n");
+  }
+  */
+  // have smth like 
+  // if (module < lastSPD) return (AliITSdigitSPD*)ITSdigits->UncheckedAt(fDigitIndex)
+  // else  (module < lastSDD) return (AliITSdigitSDD*)ITSdigits->UncheckedAt(fDigitIndex)  .... ??
+
+  //return 0;
+}
+
+//_____________________________________________________________________________
+
+
+struct Bin {
+   AliITSdigitSDD *dig;
+   int idx;
+   int digidx;
+   Bin() {dig=0; idx=-1; digidx=-1;}
+};
+
+
+struct PreCluster : public AliITSRecPointSDDnew {
+   AliITSdigitSDD* summit;
+   int idx;   
+   int npeaks;
+   int npoly;
+   float xpoly[300];
+   float ypoly[300];
+   float zpoly[300];
+   PreCluster() : AliITSRecPointSDDnew() {npeaks=npoly=0; 
+                                       for (int k=0;k<300;k++) {
+                                         xpoly[k]=ypoly[k]=zpoly[k]=0;
+				       }
+   }
+                              
+};
+
+
+//_____________________________________________________________________________
+
+//static void FindCluster(int i, int j, Bin bins[][MAXNipy], PreCluster &c) 
+static void FindCluster(int i, int j, Bin *bins, PreCluster &c, int thresh) 
+
+{
+
+  //
+  // Find clusters
+  //
+
+  //Bin& b=bins[i][j];
+  Bin& b=bins[i*MAXNipy+j];
+  Int_t q=b.dig->fSignal - thresh;
+
+  printf("i j q %d %d %d\n",i,j,q);
+
+  //  if (b.idx >= 0 && b.idx != c.idx) {
+  if (b.idx >= 0 && b.idx > c.idx) {
+    c.idx=b.idx;
+    c.npeaks++;
+  }
+  
+  if (q > TMath::Abs(c.summit->fSignal)) c.summit=b.dig;
+
+  // get pad coordinates and prepare the up and down steps   
+
+  Float_t xl[3], dx[3];
+  AliITSdisplay *display=(AliITSdisplay*)gAlice->Display();
+  display->GetPadCxy(i,j,xl,dx);
+
+  // calculate center of gravity
+  c.npoly++;
+  c.fMulDigits++;
+  c.fDigitsList[c.npoly-1]=b.digidx;
+
+  //printf("npoly c.fDigitsList[c.npoly-1] %d %d \n",c.npoly,c.fDigitsList[c.npoly-1]);
+
+  if (c.npoly > 300 ) {
+    printf("FindCluster - npoly >300,  npoly %d \n",c.npoly);
+    c.npoly=300;
+  }
+  c.xpoly[c.npoly-1]=xl[0];
+  c.ypoly[c.npoly-1]=xl[1];
+  c.zpoly[c.npoly-1]=xl[2];
+
+  c.fX += q*xl[0];
+  c.fZ += q*xl[2];
+  c.fY =  xl[1];
+  c.fQ += q;
+  
+  b.dig = 0;  b.idx = c.idx;
+
+  /*
+  // left and right  
+  if (i && bins[i-1][j].dig) FindCluster(i-1,j,bins,c);
+  if (i < MAXNipx && bins[i+1][j].dig) FindCluster(i+1,j,bins,c);
+  // up and down
+  if (j+1 < MAXNipy && bins[i][j+1].dig) FindCluster(i,j+1,bins,c);
+  if (j && bins[i][j-1].dig) FindCluster(i,j-1,bins,c);
+  */
+  // left and right  
+  if (i && bins[(i-1)*MAXNipy+j].dig) FindCluster(i-1,j,bins,c,thresh);
+  if (i < MAXNipx && bins[(i+1)*MAXNipy+j].dig) FindCluster(i+1,j,bins,c,thresh);
+  // up and down
+  if (j+1 < MAXNipy && bins[i*MAXNipy+(j+1)].dig) FindCluster(i,j+1,bins,c,thresh);
+  if (j && bins[i*MAXNipy+(j-1)].dig) FindCluster(i,j-1,bins,c,thresh);
+
+}
+
+//_____________________________________________________________________________
+void AliITSpoints::GetCenterOfGravity()
+{
+  //
+  // simple ITS cluster finder from digits -- finds neighbours and 
+  // calculates center of gravity for the cluster
+  //
+
+  const int THRESHOLD=20;
+
+  Bin *sBin=new Bin[MAXNipx*MAXNipy];
+  //else memset(sBin,0,sizeof(Bin)*MAXNipx*MAXNipy);
+  //printf("sBin %p\n",sBin);
+
+
+  //Bin bins[MAXNipx][MAXNipy]; 
+
+  AliITSdisplay *display=(AliITSdisplay*)gAlice->Display();
+  Int_t module=display->GetModule(); // or module=fModuleIndex;
+  Int_t layer=display->GetLayer();
+  Int_t id=(Int_t)((layer-1)/2);
+   
+  AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
+
+  TClonesArray *ITSdigits  = ITS->DigitsAddress(id);
+  Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
+  //gAlice->TreeD()->GetEvent(nent-nofmodules+module-1);
+  gAlice->TreeD()->GetEvent(module);
+  Int_t ndigits = ITSdigits->GetEntriesFast();
+  if (fDigitIndex < 0 || fDigitIndex >= ndigits) return;
+
+  AliITSdigitSDD  *dig;
+  dig=(AliITSdigitSDD*)ITSdigits->UncheckedAt(fDigitIndex);
+  Int_t ipx=dig->fCellX;
+  Int_t ipy=dig->fCellY;
+  //bins[ipx][ipy].dig=dig;
+  sBin[ipx*MAXNipy+ipy].dig=dig;
+  //printf("ipx, ipy, Sbin.dig %d %d %p\n",ipx,ipy,sBin[ipx*MAXNipy+ipy].dig);
+    
+  int ndig;
+  int ncls=0;
+  for (ndig=0;ndigUncheckedAt(ndig);
+    int i=dig->fCellX; int j=dig->fCellY;
+    //printf("ndig i j %d %d %d \n",ndig,i,j);
+    //bins[i][j].dig=dig;
+    sBin[i*MAXNipy+j].dig=dig;
+    sBin[i*MAXNipy+j].digidx=ndig;
+  }
+  //PreCluster c; c.summit=bins[ipx][ipy].dig; c.idx=ncls;
+  // FindCluster(ipx, ipy, bins, c);
+   PreCluster c; c.summit=sBin[ipx*MAXNipy+ipy].dig; c.idx=ncls;
+   FindCluster(ipx, ipy, sBin, c, 0);
+    
+   if (c.npeaks>1) {
+      printf("GetCenterOfGravity -- more than one peak");
+   }
+   c.fX /= c.fQ;
+   c.fZ /= c.fQ;
+   ncls++;
+
+   AliITSpoints *points = 0;
+   points = new AliITSpoints(1);
+   points->SetMarkerColor(kYellow);
+   points->SetMarkerStyle(5);
+   points->SetMarkerSize(1.);
+   points->SetPoint(0,c.fX,c.fY,c.fZ);
+   points->SetParticle(-1);
+   points->Draw();
+
+   TPolyLine3D *pline=0; 
+
+   /*
+   pline=new TPolyLine3D(c.npoly);
+   Int_t np=c.npoly;
+   TVector *xp=new TVector(c.npoly);
+   TVector *yp=new TVector(c.npoly);
+   TVector *zp=new TVector(c.npoly);
+   for (int i=0;iSetPoint(i,(*xp)(i),(*yp)(i),(*zp)(i));
+     //printf("np, i, xp, yp, zp %d %d %f %f %f \n",np,i,(*xp)(i),(*yp)(i),(*zp)(i));
+   }
+   */
+   /*
+   delete xp;
+   delete yp;
+   delete zp;
+   */ 
+
+   //if (fConnect) {
+      pline=new TPolyLine3D(c.npoly,c.xpoly,c.ypoly,c.zpoly);
+      pline->SetLineColor(kWhite);
+      pline->Draw();
+      //}
+
+
+
+   for (int k=0;kDisplay();
+  Int_t module=display->GetModule(); // or module=fModuleIndex;
+  Int_t layer=display->GetLayer();
+  Int_t id=(Int_t)((layer-1)/2);
+   
+  AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
+
+  TClonesArray *ITSdigits  = ITS->DigitsAddress(id);
+  Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
+  //gAlice->TreeD()->GetEvent(nent-nofmodules+module-1);
+  gAlice->TreeD()->GetEvent(module);
+  Int_t ndigits = ITSdigits->GetEntriesFast();
+  if (fDigitIndex < 0 || fDigitIndex >= ndigits) return;
+
+  AliITSdigitSDD  *dig;
+  dig=(AliITSdigitSDD*)ITSdigits->UncheckedAt(fDigitIndex);
+  Int_t ipx=dig->fCellX;
+  Int_t ipy=dig->fCellY;
+  lBin[ipx*MAXNipy+ipy].dig=dig;
+    
+  int ndig;
+  int ncls=0;
+
+  const int kMaxNeighbours=4;
+  
+  for (ndig=0;ndigUncheckedAt(ndig);
+    int i=dig->fCellX; int j=dig->fCellY;
+    //printf("ndig i j %d %d %d \n",ndig,i,j);
+    lBin[i*MAXNipy+j].dig=dig;
+    lBin[i*MAXNipy+j].digidx=ndig;
+  }
+   PreCluster c; c.summit=lBin[ipx*MAXNipy+ipy].dig; c.idx=ncls;
+   FindCluster(ipx, ipy, lBin, c, 0);
+    
+   printf("finished FindCluster !!!\n");
+
+   Int_t fMul=c.npoly;
+   printf("fMul %d \n",fMul);
+   AliITSdigitSDD* digt;
+
+  int fIx[fMul];
+  int fIy[fMul];
+  int fSortIx[fMul];
+  int fSortIy[fMul];
+  int fQ[fMul];
+  int fQini[fMul];
+  int fIndLocal[fMul];
+  int fIndSaddle[fMul];
+  AliITSdigitSDD*    fDig[fMul];        // current list of digits 
+
+  for (int i=0; iUncheckedAt(idx);
+        fDig[i]=digt;
+	fIx[i]= digt->fCellX;
+	fIy[i]= digt->fCellY;
+	fSortIx[i]= digt->fCellX;
+	fSortIy[i]= digt->fCellY;
+	fQini[i] = digt->fSignal;
+  }
+
+    Int_t idx_sort[fMul];
+
+    TMath::Sort(fMul,fSortIy,idx_sort,0);
+    Int_t tmin=fIy[idx_sort[0]];
+    Int_t tmax=fIy[idx_sort[fMul-1]];
+
+    TMath::Sort(fMul,fSortIx,idx_sort,0);
+    Int_t amin=fIx[idx_sort[0]];
+    Int_t amax=fIx[idx_sort[fMul-1]];
+    //printf("tmin tmax amin amax %d %d %d %d\n",tmin,tmax,amin,amax);
+
+
+   AliITSMapA2 *sMap=display->GetMap();
+
+   Int_t nt=tmax-tmin;
+   Int_t nbinx=amax-amin;
+
+   float **source = new float* [nbinx+1];
+   for(int i=0;iGetSignal(i,j);
+         Qsmooth[i-amin][j-tmin]=sMap->GetSignal(i,j);
+	 //printf("i j Qsmooth signal map %d %d %f %f\n",i,j,Qsmooth[i-amin][j-tmin],sMap->GetSignal(i,j));
+         temp[j-tmin]=sMap->GetSignal(i,j);
+     }
+     h1->SmoothArray(nt+1,temp,1);
+     for (int j=tmin;j<=tmax;j++) {
+         Qsmooth[i-amin][j-tmin]=temp[j-tmin];
+	 //printf("i j Qsmooth temp %d %d %f %f\n",i,j,Qsmooth[i-amin][j-tmin],temp[j-tmin]);
+     }
+
+   }
+
+
+//
+//  Find local maxima//
+    int fNLocal=0;
+    int fNSaddle=0;
+    Bool_t IsLocal[fMul];
+    Bool_t IsSaddle[fMul];
+    Int_t AssocPeak[fMul];
+    Int_t nn;
+    Int_t Qneighb[2*kMaxNeighbours];
+    Int_t X[2*kMaxNeighbours], Y[2*kMaxNeighbours];
+    for (int i=0; iamax || Y[j]tmax) continue;
+            Qneighb[j]=(Int_t)Qsmooth[X[j]-amin][Y[j]-tmin];
+	}
+        int nlzero=0;
+	for (int j=0; j fQ[i] || nlzero>=2) { //???
+	    if (Qneighb[j] > fQ[i] ) {
+	      //printf("i j %d %d  local kFALSE Qneighb fQ %d %d\n",i,j,Qneighb[j],fQ[i]);
+		IsLocal[i]=kFALSE;
+		break;
+//
+// handle special case of neighbouring pads with equal signal
+	     } else if (Qneighb[j] == fQ[i]) {
+		if (fNLocal >0) {
+		    for (Int_t k=0; k= tmin && j+2 <= tmax && (fQ[i] == Qsmooth[X[j]-amin][Y[j-2]-tmin]) || (fQ[i] == Qsmooth[X[j]-amin][Y[j+2]-tmin]))
+			{
+			    IsLocal[i]=kFALSE;
+			} 
+		    } // loop over local maxima
+		} // are there are already local maxima
+	    } // IsLocal
+	} // loop over neighb
+
+	// find saddle points
+        int nzero=0; int nlower=0;
+	for (int j=0; jamax || Y[j]tmax) continue;
+            Qneighb[j]=(int)source[X[j]-amin][Y[j]-tmin];
+	    if (!Qneighb[j] || !fQ[i] || !fQini[i]) {nzero++;continue;}
+	    //if (!fQ[i] || Qneighb[j]<4 || !fQini[i]) {nzero++;continue;}
+	    if (Qneighb[j] < fQ[i] ) {
+	      //printf("fIx fIy X[j] Y[j] %d %d %d %d  saddle kFALSE Qneighb fQ %d %d\n",fIx[i],fIy[i],X[j],Y[j],Qneighb[j],fQ[i]);
+              nlower++;
+              
+	      IsSaddle[i]=kFALSE;
+	      break;
+//
+// handle special case of neighbouring pads with equal signal
+	      // this is dangerous for saddle points ! better out !!
+	    } else if (Qneighb[j] == fQ[i]) {
+		if (fNSaddle >0) {
+		    for (Int_t k=0; k0) {
+	  //printf(" i fNLocal nlzero %d %d %d\n",i,fNLocal,nlzero);
+	    fIndLocal[fNLocal]=i;
+	    fNLocal++;
+	} else fQ[i]=0;
+	// Maxima should not be on the edge
+	//if (IsSaddle[i] && fQ[i]>0 && !nzero ) {
+	if (IsSaddle[i] && fQini[i]>0) {
+	  //printf(" i fNSaddle nzero %d %d %d\n",i,fNSaddle,nzero);
+          if (fIy[i]-1 < tmin || fIy[i]+1 > tmax) continue;
+	  if (source[fIx[i]-amin][fIy[i]-1-tmin] && source[fIx[i]-amin][fIy[i]+1-tmin]) {  
+	    fIndSaddle[fNSaddle]=i;
+	    fNSaddle++;
+	  }
+	}
+    } // loop over all digits
+    printf("fNLocal %d  fNSaddle %d fMul %d \n",fNLocal,fNSaddle,fMul);
+
+
+    // take the highest local maxima and spread the charge, i.e. define the
+    // response 
+
+    Int_t idx=TMath::LocMax(fMul,fQ);
+    int thresh=0;
+    int qsaddle[fNSaddle];
+    if (fNSaddle) {
+       for (int i=0;i2 and should apply only to
+    // clusters with fNLocal==2
+
+    Float_t xc[fNLocal], yc[fNLocal], zc[fNLocal];
+
+    if (fNLocal > 1 && fNSaddle) {
+      for (int i=0; i thresh+3) lBin[fIx[i]*MAXNipy+fIy[i]].dig=fDig[i];
+          else lBin[fIx[i]*MAXNipy+fIy[i]].dig=0;
+	  printf("fDig %p \n",fDig[i]);
+
+	  printf("i j source %d %d %f lBin %p \n",fIx[i],fIy[i],source[fIx[i]-amin][fIy[i]-tmin],lBin[fIx[i]*MAXNipy+fIy[i]].dig);
+      }
+
+      for (int i=0; ifSignal);
+	printf("%p  \n",lBin[ipxl*MAXNipy+ipyl].dig);
+
+	PreCluster cnew; cnew.summit=lBin[ipxl*MAXNipy+ipyl].dig; cnew.idx=ncls;
+	printf("q %p %d \n",fDig[fIndLocal[i]],lBin[ipx*MAXNipy+ipy].dig->fSignal);
+	//FindCluster(ipx, ipy, lBin, cnew, 2*thresh+1); // it's further away
+	FindCluster(ipxl, ipyl, lBin, cnew, 0);
+	printf("finish FindCluster i %d\n",i);
+	cnew.fX /= cnew.fQ;
+	cnew.fZ /= cnew.fQ;
+	ncls++;
+	printf("i cnew.fX cnew.fY cnew.fZ %d %f %f %f\n",i,cnew.fX, cnew.fY, cnew.fZ);
+
+	xc[i]=cnew.fX;
+	yc[i]=cnew.fY;
+	zc[i]=cnew.fZ;
+
+	
+        Int_t fMulnew=cnew.npoly;
+	printf("fMulnew %d \n",fMulnew);
+
+	for (int j=0; jUncheckedAt(idx);
+	    fDig[j]=digt;
+	    //printf("digt %p \n",digt);
+	    fIx[j]= digt->fCellX;
+	    fIy[j]= digt->fCellY;
+	    fSortIx[j]= digt->fCellX;
+	    fSortIy[j]= digt->fCellY;
+	    fQini[j] = digt->fSignal;
+	    // printf("i fIx fIy fQini %d %d %d %d\n",j,fIx[j],fIy[j],fQini[j]);
+	  }
+
+	Int_t idx_sort[fMulnew];
+
+	TMath::Sort(fMulnew,fSortIy,idx_sort,0);
+	Int_t tmin=fIy[idx_sort[0]];
+	Int_t tmax=fIy[idx_sort[fMulnew-1]];
+    
+        if (ipy-tmin != tmax-ipy) {
+             printf("non-symetric cluster in time direction\n");
+	     // do something - take Local maxima coord
+	} else {
+            // take cog coord
+	}
+        printf("ipy-tmin tmax-ipy %d %d\n",ipy-tmin, tmax-ipy);
+
+	TMath::Sort(fMulnew,fSortIx,idx_sort,0);
+	Int_t amin=fIx[idx_sort[0]];
+	Int_t amax=fIx[idx_sort[fMulnew-1]];
+
+        if (ipxl-amin != amax-ipxl) {
+             printf("non-symetric cluster in anode direction\n");
+	     // do something - take Local maxima coord
+	} else {
+            // take cog coord
+	}
+        printf("ipxl-amin amax-ipxl %d %d\n",ipxl-amin, amax-ipxl);
+
+	printf("inside loop over local maxima: i ipxl ipyl %d %d %d\n",i,ipxl,ipyl);
+      } // loop over local maxima
+
+    } // if fNLocal
+
+
+    if (fNLocal == 1) {
+        int ipx1=fIx[fIndLocal[0]]; int ipy1=fIy[fIndLocal[0]];
+        if (ipy1-tmin != tmax-ipy1) {
+             printf("non-symetric cluster in time direction\n");
+	     // do something - take Local maxima coord or fit
+	} else {
+            // take cog coord or fit
+	}
+        printf("ipy1-tmin tmax-ipy1 %d %d\n",ipy1-tmin, tmax-ipy1);
+
+        if (ipx1-amin != amax-ipx1) {
+             printf("non-symetric cluster in anode direction\n");
+	     // do something - take Local maxima coord or fit
+	} else {
+            // take cog coord or fit
+	}
+        printf("ipx1-amin amax-ipx1 %d %d\n",ipx1-amin, amax-ipx1);
+    }
+
+
+    printf("Here! fNLocal fNSaddle %d %d\n",fNLocal,fNSaddle);
+   
+   AliITSpoints *points = 0;
+   for (int i=0; iSetMarkerColor(kYellow);
+	points->SetMarkerStyle(5);
+	points->SetMarkerSize(1.);
+	points->SetPoint(0,xc[i],yc[i],zc[i]);
+	points->SetParticle(-1);
+	points->Draw();
+   }
+
+
+   //points = new AliITSpoints(fNLocal);
+   for (int i=0; iSetMarkerColor(kGreen);
+       points->SetMarkerStyle(5);
+       points->SetMarkerSize(1.5);
+       points->SetPoint(0,c.xpoly[idx],c.ypoly[idx],c.zpoly[idx]);
+       points->SetParticle(-1);
+       points->Draw();
+   }
+   //points = new AliITSpoints(fNSaddle);
+   for (int i=0; iSetMarkerColor(kWhite);
+       points->SetMarkerStyle(5);
+       points->SetMarkerSize(1.5);
+       points->SetPoint(0,c.xpoly[idx],c.ypoly[idx],c.zpoly[idx]);
+       points->SetParticle(-1);
+       points->Draw();
+   }
+
+
+   for (int k=0;k
 #include 
+#include 
+
 #include "AliITSsegmentation.h"
 
 class AliITSgeom;
@@ -15,6 +17,9 @@ class AliITSgeom;
 class AliITSresponse :
 public TObject {
  public:
+
+
+    virtual ~AliITSresponse() {}
     //
     // Configuration methods
     //
@@ -24,46 +29,46 @@ public TObject {
     // Get maximum Adc-count value
     virtual Float_t MaxAdc()  {return 0.;}                       
 
-    // Set maximum Adc-magic value
+    // Set maximum Adc-top value
     virtual void    SetMagicValue(Float_t p1) {}
-    // Get maximum Adc-magic value
+    // Get maximum Adc-top 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.;}
+    virtual void    SetDiffCoeff(Float_t, Float_t) {}
+    // Get diffusion coefficients
+    virtual void    DiffCoeff(Float_t &,Float_t &) {}
 
     // 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;
+    virtual void    SetDataType(const char *data) {}
     // Get data type
-    virtual char  *DataType()                =0; 
+    virtual const char  *DataType() const {return "";} 
 
 
  
-    // 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 ...
+    // Set parameters options: "same" or read from "file" or "SetInvalid" or ...
+    virtual void   SetParamOptions(const char* opt1,const char* opt2) {}
+    // Set noise parameters 
+    virtual void   SetNoiseParam(Float_t, Float_t) {}
     // Number of parameters to be set
     virtual  void   SetNDetParam(Int_t) {}
+    // Set detector parameters: gain, coupling ...
     virtual  void   SetDetParam(Float_t *) {}
 
     // Parameters options
-    virtual void   ParamOptions(Option_t *&, Option_t *&) {}
+    virtual void   ParamOptions(char *,char*) {}
     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) {}
+    // Zero-suppression option - could be 1D, 2D or non-ZeroSuppressed 
+    virtual void   SetZeroSupp(const char* opt) {}
     // Get zero-suppression option
-    virtual Option_t   *ZeroSuppOption() {return "";}
+    virtual const char *ZeroSuppOption() const {return "";}
      // Set thresholds
     virtual void   SetThresholds(Float_t, Float_t) {}
     virtual void   Thresholds(Float_t &, Float_t &) {}
@@ -72,9 +77,9 @@ public TObject {
     virtual Int_t  MinVal() {return 0;};
 
     // Set filenames
-    virtual void   SetFilenames(char *,char *,char *) {}
+    virtual void   SetFilenames(const char *f1,const char *f2,const char *f3) {}
     // Filenames
-    virtual void   Filenames(const char *, const char *,const char *) {}
+    virtual void   Filenames(char*,char*,char*) {}
 
 
     virtual Float_t DriftSpeed() {return 0.;}
diff --git a/ITS/AliITSresponseSDD.cxx b/ITS/AliITSresponseSDD.cxx
index c6d6049c141..66cd413f1c0 100644
--- a/ITS/AliITSresponseSDD.cxx
+++ b/ITS/AliITSresponseSDD.cxx
@@ -13,14 +13,8 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-#include 
-
-#include "AliITSgeom.h"
 #include "AliITSresponseSDD.h"
-#include "AliITS.h"
-#include "AliRun.h"
 
-class AliITS;
 
 //___________________________________________
 ClassImp(AliITSresponseSDD)	
@@ -30,8 +24,8 @@ AliITSresponseSDD::AliITSresponseSDD()
   // constructor
    SetMaxAdc();
    SetDiffCoeff();
-   SetQref();
    SetDriftSpeed();
+   SetNSigmaIntegration();
    // SetClock();
    SetNoiseParam();
    SetMagicValue();
@@ -47,17 +41,18 @@ AliITSresponseSDD::AliITSresponseSDD()
 //__________________________________________________________________________
 AliITSresponseSDD::AliITSresponseSDD(const AliITSresponseSDD &source){
   //     Copy Constructor 
-  Int_t i;
   if(&source == this) return;
+  Int_t i;
   for(i=0;i<8;i++){this->fCPar[i] = source.fCPar[i];}
   this->fNoise = source.fNoise;
   this->fBaseline = source.fBaseline;
   this->fTopValue = source.fTopValue;
   this->fTemperature = source.fTemperature;
   this->fDriftSpeed = source.fDriftSpeed;
+  this->fNsigmas = source.fNsigmas;
   this->fMaxAdc = source.fMaxAdc;
   this->fDiffCoeff = source.fDiffCoeff;
-  this->fQref = source.fQref;
+  this->fDiffCoeff1 = source.fDiffCoeff1;
   this->fZeroSuppFlag = source.fZeroSuppFlag;
   this->fMinVal = source.fMinVal;
   this->fWrite = source.fWrite;
@@ -70,17 +65,18 @@ AliITSresponseSDD::AliITSresponseSDD(const AliITSresponseSDD &source){
 AliITSresponseSDD& 
   AliITSresponseSDD::operator=(const AliITSresponseSDD &source) {
   //    Assignment operator
-  Int_t i;
   if(&source == this) return *this;
+  Int_t i;
   for(i=0;i<8;i++){this->fCPar[i] = source.fCPar[i];}
   this->fNoise = source.fNoise;
   this->fBaseline = source.fBaseline;
   this->fTopValue = source.fTopValue;
   this->fTemperature = source.fTemperature;
   this->fDriftSpeed = source.fDriftSpeed;
+  this->fNsigmas = source.fNsigmas;
   this->fMaxAdc = source.fMaxAdc;
   this->fDiffCoeff = source.fDiffCoeff;
-  this->fQref = source.fQref;
+  this->fDiffCoeff1 = source.fDiffCoeff1;
   this->fZeroSuppFlag = source.fZeroSuppFlag;
   this->fMinVal = source.fMinVal;
   this->fWrite = source.fWrite;
@@ -92,8 +88,9 @@ AliITSresponseSDD&
 void AliITSresponseSDD::SetCompressParam(Int_t  cp[8])
 {
   // set compression param
+
     Int_t i;
-    for(i=0; i<8; i++) {
+    for (i=0; i<8; i++) {
 	fCPar[i]=cp[i];
 	//printf("\n CompressPar %d %d \n",i,fCPar[i]);
 	
@@ -102,8 +99,9 @@ void AliITSresponseSDD::SetCompressParam(Int_t  cp[8])
 void AliITSresponseSDD::GiveCompressParam(Int_t  cp[8])
 {
   // give compression param
+
     Int_t i;
-    for(i=0; i<8; i++) {
+    for (i=0; i<8; i++) {
 	cp[i]=fCPar[i];
     }
 }
diff --git a/ITS/AliITSresponseSDD.h b/ITS/AliITSresponseSDD.h
index fbdf687021f..44225aa23d8 100644
--- a/ITS/AliITSresponseSDD.h
+++ b/ITS/AliITSresponseSDD.h
@@ -19,7 +19,7 @@ public:
   AliITSresponseSDD(const AliITSresponseSDD &source); // copy constructor
   AliITSresponseSDD& operator=(const AliITSresponseSDD &source); // ass. op.
   
-  virtual void    SetMaxAdc(Float_t p1=1023) {
+  virtual void    SetMaxAdc(Float_t p1=1024) {
     // Adc-count saturation value
     fMaxAdc=p1;
   }
@@ -28,33 +28,27 @@ public:
     return fMaxAdc;
   }                       
   
-  virtual void    SetMagicValue(Float_t p1=450.) {
-    // Set maximum Adc-magic value
+  virtual void    SetMagicValue(Float_t p1=1024) {
+    // Set maximum Adc-top value
     fTopValue=p1;
+    //it was 96.95
   }
   virtual Float_t MagicValue()  {
-    // Get maximum Adc-magic value
+    // Get maximum Adc-top value
     return fTopValue;
   }                       
   
-  virtual void    SetDiffCoeff(Float_t p1=5.) {
-    // Diffusion coefficient
+  virtual void    SetDiffCoeff(Float_t p1=2.8,Float_t p2=28.) {
+    // Diffusion coefficients
     fDiffCoeff=p1;
+    fDiffCoeff1=p2;
   }
-  virtual Float_t DiffCoeff() {
-    // Get diffusion coefficient
-    return fDiffCoeff;
+  virtual void DiffCoeff(Float_t&diff,Float_t&diff1) {
+    // Get diffusion coefficients
+    diff = fDiffCoeff;
+    diff1 = fDiffCoeff1;
   } 
   
-  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;
@@ -73,25 +67,25 @@ public:
     return fTemperature;
   } 
   
-  virtual void    SetDataType(char *data="simulated") {
+  virtual void    SetDataType(const char *data="simulated") {
     // Type of data - real or simulated
     fDataType=data;
   }
-  virtual char  *DataType() {
+  virtual const char  *DataType() const {
     // Get data type
-    return fDataType;
+    return fDataType.Data();
   } 
   
-  virtual void SetParamOptions(Option_t *opt1="same",Option_t *opt2="same"){
+  virtual void SetParamOptions(const char *opt1="same",const char *opt2="same"){
     // Parameters: "same" or read from "file" 
     fParam1=opt1; fParam2=opt2;
   }
-  virtual void   ParamOptions(Option_t *&opt1,Option_t *&opt2) {
+  virtual void   ParamOptions(char *opt1,char *opt2) {
     // options
-    opt1=fParam1; opt2=fParam2;
+    strcpy(opt1,fParam1.Data()); strcpy(opt2,fParam2.Data());
   }
   
-  virtual  void  SetNoiseParam(Float_t n=3., Float_t b=20.){
+  virtual  void  SetNoiseParam(Float_t n=1.8, Float_t b=20.){
     // Noise and baseline
     fNoise=n; fBaseline=b;
   }   
@@ -100,13 +94,13 @@ public:
     n=fNoise; b=fBaseline;
   }   
   
-  virtual void    SetZeroSupp(Option_t *opt="2D") {
+  virtual void    SetZeroSupp (const char *opt="2D") {
     // Zero-suppression option - could be 1D, 2D or non-ZS 
     fOption=opt;
   }
-  virtual Option_t *ZeroSuppOption() {
+  virtual const char *ZeroSuppOption() const {
     // Get zero-suppression option
-    return fOption;
+    return fOption.Data();
   }
   virtual  void  SetMinVal(Int_t mv=4) {
     // Min value used in 2D - could be used as a threshold setting
@@ -117,13 +111,14 @@ public:
     return fMinVal;
   }
   
-  virtual void   SetFilenames(char *f1=0,char *f2=0, char *f3=0) {
+  virtual void   SetFilenames(const char *f1="",const char *f2="",const char *f3="") {
     // Set filenames - input, output, parameters ....
     fFileName1=f1; fFileName2=f2; fFileName3=f3;
   }
-  virtual void   Filenames(const char*input,const char*baseline,const char*param) {
+  virtual void   Filenames(char *input,char *baseline,char *param) {
     // Filenames
-    input=fFileName1; baseline=fFileName2; param=fFileName3;
+   strcpy(input,fFileName1.Data());  strcpy(baseline,fFileName2.Data());  
+   strcpy(param,fFileName3.Data());
   }     
   
   
@@ -142,12 +137,13 @@ public:
   
   //  
   // Detector type response methods
-  virtual void    SetNSigmaIntegration(Float_t p1) {
+  virtual void    SetNSigmaIntegration(Float_t p1=4.) {
     // Set number of sigmas over which cluster disintegration is performed
+    fNsigmas=p1;
   }
   virtual Float_t NSigmaIntegration() {
     // Get number of sigmas over which cluster disintegration is performed
-    return 0.;
+    return fNsigmas;
   }
   virtual void    SetSigmaSpread(Float_t p1, Float_t p2) {
     // Set sigmas of the charge spread function
@@ -169,8 +165,6 @@ public:
 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
@@ -179,28 +173,23 @@ protected:
   Float_t   fDriftSpeed;     // Drift velocity
   
   Float_t    fMaxAdc;        // Adc saturation value
-  Float_t    fDiffCoeff;     // Diffusion Coefficient
-  Float_t    fQref;          // Coulomb repulsion
+  Float_t    fDiffCoeff;     // Diffusion Coefficient (scaling the time)
+  Float_t    fDiffCoeff1;    // Diffusion Coefficient (constant term)
+  Float_t    fNsigmas;       // Number of sigmas over which charge disintegration 
+                             // is performed 
   
   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 
-  
-  char*         fDataType;         //!
-				   // input keys : run, module #
-  char*         fFileName1;        //!
-                                   // input keys : run, module #
-  char*         fFileName2;        //!
-                                   // baseline & noise val or output coded                                        // signal or monitored bgr.
-  char*         fFileName3;        //!
-                                   // param values or output coded signal 
+  TString    fOption;        // Zero-suppresion option (1D, 2D or none)
+  TString    fParam1;        // Read baselines from file option
+  TString    fParam2;        // Read compression algo thresholds from file 
+  
+  TString         fDataType;         // data type - real or simulated
+  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 
     
diff --git a/ITS/AliITSresponseSPD.h b/ITS/AliITSresponseSPD.h
index 73e4f24ff8d..f47818c0bc3 100644
--- a/ITS/AliITSresponseSPD.h
+++ b/ITS/AliITSresponseSPD.h
@@ -1,8 +1,8 @@
 #ifndef ALIITSRESPONSESPD_H
 #define ALIITSRESPONSESPD_H
 
-#include "AliITSsegmentation.h"
 #include "AliITSresponse.h"
+
 //----------------------------------------------
 //
 // ITS response class for SPD
@@ -18,23 +18,23 @@ public:
   //
   // Configuration methods
   //
-  virtual void    SetDiffCoeff(Float_t p1=0.00433) {
+  virtual void    SetDiffCoeff(Float_t p1=0.00433,Float_t dummy=0.) {
     // Diffusion coefficient
     fDiffCoeff=p1;
   }
-  virtual Float_t DiffCoeff() {
+  virtual void DiffCoeff(Float_t &diffc,Float_t &dummy) {
     // Get diffusion coefficient
-    return fDiffCoeff;
+    diffc= fDiffCoeff;
   }
-  virtual  void   SetNoiseParam(Float_t n=0., Float_t b=0.) {
-    // set noise
+  virtual  void   SetNoiseParam(Float_t n=200., Float_t b=0.) {
+    // set noise and baseline
     fNoise=n; fBaseline=b;
   }   
   virtual  void   GetNoiseParam(Float_t &n, Float_t &b) {
-    // get noise
+    // get noise and baseline
     n=fNoise; b=fBaseline;
   }   
-  virtual void     SetMinVal(Int_t p1=0) {
+  virtual void     SetMinVal(Int_t p1=2000) {
     // Zero-suppression option threshold 
     fThreshold=p1;
   }
@@ -42,13 +42,13 @@ public:
     // Get zero-suppression threshold
     return fThreshold;
   }
-  virtual void    SetDataType(char *data="simulated") {
+  virtual void    SetDataType(const char *data="simulated") {
     // Type of data - real or simulated
     fDataType=data;
   }
-  virtual char  *DataType() {
+  virtual const char  *DataType() const {
     // Get data typer
-    return fDataType;
+    return fDataType.Data();
   } 
   
   ClassDef(AliITSresponseSPD,1) // SPD response
@@ -60,8 +60,7 @@ public:
   Float_t fBaseline;        // Baseline value
   Int_t fThreshold;         // Zero-Suppression threshold
   
-  char* fDataType;          //!
-                            // Type of data - real or simulated
+  TString fDataType;        // Type of data - real or simulated
 };
 
 #endif
diff --git a/ITS/AliITSresponseSSD.cxx b/ITS/AliITSresponseSSD.cxx
index fb0b6ec9f10..9a8b47dbd8c 100644
--- a/ITS/AliITSresponseSSD.cxx
+++ b/ITS/AliITSresponseSSD.cxx
@@ -91,7 +91,7 @@ void AliITSresponseSSD::SetDetParam(Float_t  *par)
 {
   // set det param
   Int_t i;
-  for(i=0; iGetModule("ITS"))->GetITSgeom();
+   }
    AliITSgeomSDD *gsdd = (AliITSgeomSDD *) (fGeom->GetShape(3,1,1));
 
    const Float_t kconv=10000.;
@@ -82,6 +86,8 @@ 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
 
+    if(iX >= fNanodes) printf("iX > fNanodes %d %d\n",iX,fNanodes);
+    if(iZ >= fNsamples) printf("iZ > fNsamples %d %d\n",iZ,fNsamples);
     *Nlist=4;
     Xlist[0]=Xlist[1]=iX;
     if(iX) Xlist[2]=iX-1;
@@ -96,7 +102,7 @@ Neighbours(Int_t iX, Int_t iZ, Int_t* Nlist, Int_t Xlist[4], Int_t Zlist[4]){
 
 }
 //------------------------------
-void AliITSsegmentationSDD::GetCellIxz(Float_t &x,Float_t &z,Int_t &timebin,Int_t &anode){
+void AliITSsegmentationSDD::GetPadIxz(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
@@ -107,7 +113,7 @@ void AliITSsegmentationSDD::GetCellIxz(Float_t &x,Float_t &z,Int_t &timebin,Int_
     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);
+    anode=(Int_t)(kconv*z/fPitch) + na/2;
     if (x > 0) anode += na;
 
     timebin+=1;
@@ -116,7 +122,7 @@ void AliITSsegmentationSDD::GetCellIxz(Float_t &x,Float_t &z,Int_t &timebin,Int_
 }
 
 //------------------------------
-void AliITSsegmentationSDD::GetCellCxz(Int_t timebin,Int_t anode,Float_t &x ,Float_t &z){
+void AliITSsegmentationSDD::GetPadCxz(Int_t timebin,Int_t anode,Float_t &x ,Float_t &z){
     // Transform from cell to real local coordinates
   
     // returns x, z in cm
@@ -133,6 +139,22 @@ void AliITSsegmentationSDD::GetCellCxz(Int_t timebin,Int_t anode,Float_t &x ,Flo
 
 }
 
+//------------------------------
+void AliITSsegmentationSDD::GetPadTxz(Float_t &x,Float_t &z){
+    // Get anode and time bucket as floats - numbering from 0
+
+    // 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);
+    x=driftpath/speed/fTimeStep;
+    z=kconv*z/fPitch + (float)na/2;
+    if (x > 0) x += (float)na;
+
+}
 //------------------------------
 void AliITSsegmentationSDD::GetLocal(Int_t module,Float_t *g ,Float_t *l){
   // returns local coordinates from global
diff --git a/ITS/AliITSsegmentationSDD.h b/ITS/AliITSsegmentationSDD.h
index 8ec440895be..a701de397ca 100644
--- a/ITS/AliITSsegmentationSDD.h
+++ b/ITS/AliITSsegmentationSDD.h
@@ -22,25 +22,27 @@ public AliITSsegmentation {
     //
     // Detector size : x,z,y
   virtual  void   SetDetSize
-          (Float_t p1=35000., Float_t p2=76800., Float_t p3= 300.) 
+          (Float_t p1=35000., Float_t p2=75264., 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.) 
+    virtual void    SetPadSize(Float_t pitch=294., 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) 
+    virtual void    SetNPads(Int_t p1=256, 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);
+    virtual void    GetPadIxz(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 );
+    virtual void    GetPadCxz(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);
+    // Get anode and time bucket as floats - numbering from 0
+    virtual void    GetPadTxz(Float_t &x ,Float_t &z);
     //
     // Initialisation
     virtual void Init();
@@ -78,12 +80,12 @@ public AliITSsegmentation {
     //
     // Iterate over cells 
     // Initialiser
-    virtual void  FirstCell
+    virtual void  FirstPad
           (Float_t xhit, Float_t zhit, Float_t dx, Float_t dz) {}
     // Stepper
-    virtual void  NextCell() {}
+    virtual void  NextPad() {}
     // Condition
-    virtual Int_t MoreCells() {return 0;}
+    virtual Int_t MorePads() {return 0;}
     //
     // Current cell cursor during disintegration
     // x-coordinate
@@ -116,7 +118,7 @@ public AliITSsegmentation {
     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
+    AliITSgeom *fGeom;         //! pointer to the geometry class
     AliITSresponse *fResponse; // pointer to the response class
    
     TF1*       fCorr;          // correction function
diff --git a/ITS/AliITSsegmentationSPD.cxx b/ITS/AliITSsegmentationSPD.cxx
index 69b0d4340eb..fe309de2a05 100644
--- a/ITS/AliITSsegmentationSPD.cxx
+++ b/ITS/AliITSsegmentationSPD.cxx
@@ -79,7 +79,7 @@ Float_t ColFromZ(Float_t z) {
   } else if( z < 83600) {  
     col = 161 + (z - 70425)/pitchz;
   }   
-  return col;
+  return TMath::Abs(col);
 }
 
 //_____________________________________________________________________________
@@ -160,12 +160,12 @@ AliITSsegmentationSPD::AliITSsegmentationSPD(AliITSgeom *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;
+   Int_t i;
    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
@@ -184,8 +184,8 @@ void AliITSsegmentationSPD::Init300(){
 // 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.;
+    Int_t i;
     fNpx = 256; // The number of X pixel Cell same as in fCellSizeX array size
     fNpz = 279; // The number of Z pixel Cell same as in fCellSizeZ array size
     for(i=0;i  fNpz) iz= fNpz;
     if (ix >  fNpx) ix= fNpx;
-
     /*
     if (iz < -fNpz) iz= -fNpz;
     if (ix < -fNpx) ix=-fNpx;
@@ -275,7 +272,21 @@ void AliITSsegmentationSPD::GetCellIxz(Float_t &x,Float_t &z,Int_t &ix,Int_t &iz
 }
 
 //------------------------------
-void AliITSsegmentationSPD::GetCellCxz(Int_t ix,Int_t iz,Float_t &x,Float_t&z){
+void AliITSsegmentationSPD::GetPadTxz(Float_t &x,Float_t &z){
+//  local transformation of real local coordinates (x,z)
+//
+
+    // expects x, z in microns
+
+    // same segmentation on x
+    Float_t dpx=Dpx(0);
+
+    x /= dpx;
+    z = ColFromZ(z);
+
+}
+//------------------------------
+void AliITSsegmentationSPD::GetPadCxz(Int_t ix,Int_t iz,Float_t &x,Float_t&z){
     // Transform from pixel to real local coordinates
 
     // returns x, z in microns
diff --git a/ITS/AliITSsegmentationSPD.h b/ITS/AliITSsegmentationSPD.h
index 6c8a618499e..4cb92195a1a 100644
--- a/ITS/AliITSsegmentationSPD.h
+++ b/ITS/AliITSsegmentationSPD.h
@@ -21,18 +21,20 @@ public AliITSsegmentation {
     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);
+    virtual void    SetNPads(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);
+    virtual void    GetPadIxz
+         (Float_t x,Float_t z,Int_t &ix,Int_t &iz);
     // Transform from pixel to real coordinates
-    virtual void    GetCellCxz
+    virtual void    GetPadCxz
          (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) {}
+    // Local transformation of real local coordinates -
+    virtual void    GetPadTxz(Float_t &x ,Float_t &z);
     //
     // Initialisation
     virtual void Init();
@@ -72,7 +74,7 @@ public AliITSsegmentation {
     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.
+    AliITSgeom *fGeom;      //! local pointer to AliITSgeom.
 
   ClassDef(AliITSsegmentationSPD,1) //Segmentation class for SPD 
 
diff --git a/ITS/AliITSsegmentationSSD.cxx b/ITS/AliITSsegmentationSSD.cxx
index 63080ebd906..2d4ba2d5b51 100644
--- a/ITS/AliITSsegmentationSSD.cxx
+++ b/ITS/AliITSsegmentationSSD.cxx
@@ -25,8 +25,8 @@ AliITSsegmentationSSD::AliITSsegmentationSSD(){
    fGeom=0;
    fCorr=0;
    SetDetSize();
-   SetCellSize();
-   SetNCells();
+   SetPadSize();
+   SetNPads();
    SetAngles();
 }
 //------------------------------
@@ -35,8 +35,8 @@ AliITSsegmentationSSD::AliITSsegmentationSSD(AliITSgeom *geom){
    fGeom=geom;
    fCorr=0;
    SetDetSize();
-   SetCellSize();
-   SetNCells();
+   SetPadSize();
+   SetNPads();
    SetAngles();
    //Init(); 
 }
@@ -70,13 +70,13 @@ void AliITSsegmentationSSD::Init(){
     fDx = 2.*kconv*gssd->GetDx();
     fDz = 2.*kconv*gssd->GetDz();
     fDy = 2.*kconv*gssd->GetDy();
-    SetCellSize();
-    SetNCells();
+    SetPadSize();
+    SetNPads();
     SetAngles();
 
 }
 //-------------------------------------------------------
-void AliITSsegmentationSSD::GetCellIxz(Float_t &x,Float_t &z,Int_t &iP,Int_t &iN)
+void AliITSsegmentationSSD::GetPadIxz(Float_t x,Float_t z,Int_t &iP,Int_t &iN)
 {
   // returns P and N sided strip numbers for a given location.
 
@@ -102,7 +102,7 @@ void AliITSsegmentationSSD::GetCellIxz(Float_t &x,Float_t &z,Int_t &iP,Int_t &iN
 
 }
 //-------------------------------------------------------
-void AliITSsegmentationSSD::GetCellCxz(Int_t iP,Int_t iN,Float_t &x,Float_t &z)
+void AliITSsegmentationSSD::GetPadCxz(Int_t iP,Int_t iN,Float_t &x,Float_t &z)
 {
     // actually this is the GetCrossing(Float_t &,Float_t &) 
 
diff --git a/ITS/AliITSsegmentationSSD.h b/ITS/AliITSsegmentationSSD.h
index a85224d0049..f86e7b7e1eb 100644
--- a/ITS/AliITSsegmentationSSD.h
+++ b/ITS/AliITSsegmentationSSD.h
@@ -22,11 +22,11 @@ public AliITSsegmentation {
                         {fDx=p1; fDz=p2; fDy=p3;}
 
     // Strip size  
-    virtual void    SetCellSize(Float_t pitch=95., Float_t dummy=1.) 
+    virtual void    SetPadSize(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) 
+    virtual void    SetNPads(Int_t p1=768, Int_t dummy=1) 
                          {fNstrips=p1;}
 
 
@@ -35,10 +35,10 @@ public AliITSsegmentation {
                          {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);
+    virtual void    GetPadIxz
+    (Float_t x ,Float_t z ,Int_t   &iP,Int_t  &iN);
     // Transform from strips to real coordinates
-    virtual void    GetCellCxz
+    virtual void    GetPadCxz
     (Int_t iP, Int_t iN, Float_t &x , Float_t &z);
 
     // Transform from real global to local coordinates
@@ -79,7 +79,7 @@ public AliITSsegmentation {
   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
+  AliITSgeom *fGeom;         //! pointer to the geometry class
   TF1*       fCorr;          // correction function
   
   ClassDef(AliITSsegmentationSSD,1) //Segmentation class for SSD 
diff --git a/ITS/AliITSsimulation.h b/ITS/AliITSsimulation.h
index d773515bff0..c6b6aaa14d1 100644
--- a/ITS/AliITSsimulation.h
+++ b/ITS/AliITSsimulation.h
@@ -6,6 +6,7 @@
 class AliITSresponse;
 class AliITSsegmentation;
 class AliITSmodule;
+class TRandom;
 
 //___________________________________________________
 
@@ -24,7 +25,7 @@ public:
     // digitize module
   }
 
-  virtual void CreateFastRecPoints(AliITSmodule *mod) {
+  virtual void CreateFastRecPoints(AliITSmodule *mod,Int_t module,TRandom *rndm) {
     // create fast rec points
   }
 
diff --git a/ITS/AliITSsimulationFastPoints.cxx b/ITS/AliITSsimulationFastPoints.cxx
index 9a51c3e12a9..702a061df1c 100644
--- a/ITS/AliITSsimulationFastPoints.cxx
+++ b/ITS/AliITSsimulationFastPoints.cxx
@@ -15,170 +15,197 @@
 
 /*
 $Log$
-Revision 1.1.2.1  2000/06/11 20:16:05  barbera
-New: Fast simulation class for the ITS, class as part of new ITS code
-structure.
-
 */
+#include 
 
-#include 
 #include "AliITS.h"
+#include "AliRun.h"
 #include "AliITSsimulationFastPoints.h"
-#include "AliITSstatistics.h"
+
 
 ClassImp(AliITSsimulationFastPoints)
 
 AliITSsimulationFastPoints::AliITSsimulationFastPoints()
 {
   //constructor
-  fSx = new AliITSstatistics(2);
-  fSz = new AliITSstatistics(2);
+  fSigmaRPhi[0] = fSigmaRPhi[1] = 12e-4;
+  fSigmaRPhi[2] = fSigmaRPhi[3] = 38e-4;
+  fSigmaRPhi[4] = fSigmaRPhi[5] = 20e-4;
+  fSigmaZ[0] = fSigmaZ[1] = 70e-4;
+  fSigmaZ[2] = fSigmaZ[3] = 28e-4;
+  fSigmaZ[4] = fSigmaZ[5] = 830e-4;
+  fSigmaDe[0] = fSigmaDe[1] = 0.72e-6;
+  fSigmaDe[2] = fSigmaDe[3] = 0.90e-6;
+  fSigmaDe[4] = fSigmaDe[5] =  5e-6;
+  fThrDe[0] = fThrDe[1] = 7.2e-6;
+  fThrDe[2] = fThrDe[3] = 2.70e-6;
+  fThrDe[4] = fThrDe[5] = 10e-6;
 }
 
-//----------------------------------------------------------
-AliITSsimulationFastPoints::~AliITSsimulationFastPoints()
-{
-  //destructor
-  delete fSx;
-  delete fSz;
+//-------------------------------------------------------------
+void AliITSsimulationFastPoints::CreateFastRecPoints(AliITSmodule *mod, Int_t module, TRandom *random){
+  // Fast points simulator 
+
+   AliITS *aliITS  = (AliITS*)gAlice->GetModule("ITS");
+   AliITSgeom *gm = aliITS->GetITSgeom();
+
+   const Float_t kdEdXtoQ = 2.778e+8; 
+
+   Int_t ihit,flag,numofhits;
+   Float_t xg,yg,zg,xl,yl,zl;
+   Float_t px,py,pz;
+   //Double_t p, theta, pt, ps;
+   Float_t locals[3];
+   Float_t globals[3];
+   //Float_t xg1,yg1,zg1;
+   Double_t sigmarphi=0., sigmaz=0., sigmade=0., thrde=0.;
+   Float_t deltaXl,deltaZl,deltaDe;
+
+   Int_t hitlay, hitlad, hitdet, hitstatus, hittrack;
+   Float_t hitx, hity, hitz, hitpx, hitpy, hitpz, hitdestep;
+   
+
+   Int_t   hitstatus1, hittrack1;
+   Float_t hitx1, hity1, hitz1;
+   Float_t hitdestep1;
+
+   Float_t xMg,yMg,zMg;
+   //Float_t dx,dy,dz,ds;
+
+
+   numofhits = mod->GetNhits();
+   flag = 1;
+   for(ihit=0;ihitGetHit(ihit);
+     hit->GetPositionG(hitx1,hity1,hitz1);
+     hitstatus1 = hit->GetTrackStatus();
+     hitdestep1 = hit->GetIonization();
+
+     hittrack1 = hit->GetTrack();
+
+     mod->MedianHit(module,hitx1,hity1,hitz1,hitstatus1,xMg,yMg,zMg,flag);
+     if (flag!=1) {
+       hitx      = xMg;
+       hity      = yMg;
+       hitz      = zMg;
+       hit->GetDetectorID(hitlay,hitlad,hitdet);
+       hit->GetMomentumG(hitpx,hitpy,hitpz);            
+       hitdestep = hit->GetIonization();
+       hitstatus = hitstatus1;
+       hittrack  = hit->GetTrack();
+
+       if (hitdestep > 0) {
+	   xg = hitx;
+	   yg = hity;
+	   zg = hitz;
+           // Transform to the module local frame
+	   globals[0] = hitx;
+	   globals[1] = hity;
+	   globals[2] = hitz;
+	   gm->GtoL(hitlay,hitlad,hitdet,globals,locals);
+	   xl = locals[0];
+	   yl = locals[1];
+	   zl = locals[2];
+	   px = hitpx;
+	   py = hitpy;
+	   pz = hitpz;
+	   /*
+           // Calculate transverse momentum and pseudorapidity
+           // to allow pt and eta dependence in sigma values
+           // of the spatial resolution
+	   p  = TMath::Sqrt((px*px)+(py*py)+(pz*pz));
+	   theta = TMath::ACos(pz/p);
+	   pt = p * TMath::Sin(theta);
+	   ps = -TMath::Log(TMath::Tan(theta/2));
+	   */
+
+           // Retrieve sigma values for position and energy, and energy
+           // threshold 
+	   
+	   sigmarphi = SigmaRPhi(hitlay);
+	   sigmaz = SigmaZ(hitlay);
+	   sigmade = SigmaDe(hitlay);
+	   thrde = ThrDe(hitlay);
+	   // Randomize position and deposited energy
+           Int_t k=3*(Int_t)((hitlay-1)/2);
+
+	   deltaXl = (float)(random[k].Gaus(0,sigmarphi));
+	   deltaZl = (float)(random[k+1].Gaus(0,sigmaz));
+	   deltaDe = (float)(random[k+2].Gaus(0,sigmade));
+           // Apply energy threshold and trasform back to global reference 
+           // system
+	   if ( (hitdestep+deltaDe) > thrde ){
+	       locals[0] = xl + deltaXl;
+	       locals[1] = yl;
+	       locals[2] = zl + deltaZl;
+	       AliITSRecPoint rp;
+	       rp.fTracks[0]=hittrack;
+	       rp.fTracks[1]=0;
+	       rp.fTracks[2]=0;
+	       rp.SetX(locals[0]);
+	       rp.SetZ(locals[2]);
+	       rp.SetdEdX(hitdestep+deltaDe);
+	       rp.SetQ(kdEdXtoQ*(hitdestep+deltaDe));  // number of e
+	       rp.SetSigmaX2(sigmarphi*sigmarphi);
+	       rp.SetSigmaZ2(sigmaz*sigmaz);
+	       rp.SetProbability(1.0);
+	       aliITS->AddRecPoint(rp);
+	       /*
+	       gm->LtoG(hitlay,hitlad,hitdet,locals,globals);
+	       xg1 = globals[0];
+	       yg1 = globals[1];
+	       zg1 = globals[2];
+	       dx = TMath::Abs(xg1-hitx);
+	       dy = TMath::Abs(yg1-hity);
+	       dz = TMath::Abs(zg1-hitz);
+	       ds = TMath::Abs(deltaDe);
+	       */
+	   } // if ( (hitdestep+deltaDe)
+	   else flag=1;
+       } // if (hitdestep > 0)
+       else flag=1;
+     } // if (flag!=1)
+   }   
 
 }
+//_______________________________________________________________________
+void AliITSsimulationFastPoints::SetSigmaRPhi(Double_t  srphi[6])
+{
+  // set sigmas in rphi
 
-//-------------------------------------------------------------
-void AliITSsimulationFastPoints::CreateFastRecPoints(AliITSmodule *mod){
-  // Fast points simulator for all of the ITS.
-  Int_t   nhit,h,trk,ifirst;
-  Float_t x,y,z,t,e;// local coordinate (cm) and time of flight, and dedx.
-  Float_t x1,y1,z1;
-  AliITShit *hit;
-
-  fSx->Reset(); // Start out with things clearly zeroed
-  fSz->Reset(); // Start out with things clearly zeroed
-  e = 0.; // Start out with things clearly zeroed
-  Double_t weight=1.;
-  nhit = mod->GetNhits();
-  ifirst = 1;
-  for(h=0;hGetHit(h);
-    hit->GetPositionL(x,y,z,t);
-    if(ifirst) {x1=x;y1=y;z1=z;}
-    e += hit->GetIonization();
-    trk = hit->GetTrack();
-    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
+    Int_t i;
+    for (i=0; i<6; i++) {
+	fSigmaRPhi[i]=srphi[i];
+    }
 }
 //_______________________________________________________________________
-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::SetSigmaZ(Double_t  sz[6])
+{
+  // set sigmas in z
+
+    Int_t i;
+    for (i=0; i<6; i++) {
+	fSigmaZ[i]=sz[i];
+    }
 }
 //_______________________________________________________________________
-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::SetSigmaDe(Double_t  sde[6])
+{
+  // set sigmas in energy
+
+    Int_t i;
+    for (i=0; i<6; i++) {
+	fSigmaDe[i]=sde[i];
+    }
 }
 //_______________________________________________________________________
-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);
+void AliITSsimulationFastPoints::SetThrDe(Double_t  thrde[6])
+{
+  // set energy thersholds
+
+    Int_t i;
+    for (i=0; i<6; i++) {
+	fThrDe[i]=thrde[i];
+    }
 }
-//_______________________________________________________________________
+
diff --git a/ITS/AliITSsimulationFastPoints.h b/ITS/AliITSsimulationFastPoints.h
index 6e2e52fed6c..637edfea49a 100644
--- a/ITS/AliITSsimulationFastPoints.h
+++ b/ITS/AliITSsimulationFastPoints.h
@@ -4,24 +4,34 @@
 #include "AliITSsimulation.h"
 
 class AliITSmodule;
-class AliITSstatistics;
+class TRandom;
 
 class AliITSsimulationFastPoints : public AliITSsimulation
 {
 
 public:
   AliITSsimulationFastPoints(); // default constructor
-  virtual ~AliITSsimulationFastPoints(); 
-  void CreateFastRecPoints(AliITSmodule *mod);
+  virtual ~AliITSsimulationFastPoints() {} 
+  void CreateFastRecPoints(AliITSmodule *mod,Int_t module,TRandom *rndm);
 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);
+
+    virtual void SetSigmaRPhi(Double_t sigmarphi[6]);  
+    virtual void SetSigmaZ(Double_t sigmaz[6]);  
+    virtual void SetSigmaDe(Double_t sigmade[6]);  
+    virtual void SetThrDe(Double_t thrde[6]); 
+    Double_t SigmaRPhi(Int_t layer) {return fSigmaRPhi[layer-1];}  
+    Double_t SigmaZ(Int_t layer) {return fSigmaZ[layer-1];}  
+    Double_t SigmaDe(Int_t layer) {return fSigmaDe[layer-1];} 
+    Double_t ThrDe(Int_t layer) {return fThrDe[layer-1];} 
+
 
 private:
 
-  AliITSstatistics *fSx;   // pointer to AliITSstatistics class
-  AliITSstatistics *fSz;   // pointer to AliITSstatistics class
+    Double_t fSigmaRPhi[6];              // Sigmas in rphi for the 6 layers
+    Double_t fSigmaZ[6];                 // Sigmas in Z for the 6 layers
+    Double_t fSigmaDe[6];                // Sigmas in energy loss for the 6 layers
+    Double_t fThrDe[6];                  // Energy thresholds for the 6 layers
+
 
   ClassDef(AliITSsimulationFastPoints,1) // Fast point simulator.
 
diff --git a/ITS/AliITSsimulationFastPointsV0.cxx b/ITS/AliITSsimulationFastPointsV0.cxx
new file mode 100644
index 00000000000..b0d95787128
--- /dev/null
+++ b/ITS/AliITSsimulationFastPointsV0.cxx
@@ -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$
+*/
+
+#include 
+#include 
+
+
+#include "AliITS.h"
+#include "AliITSsimulationFastPointsV0.h"
+#include "AliITSstatistics.h"
+
+ClassImp(AliITSsimulationFastPointsV0)
+
+AliITSsimulationFastPointsV0::AliITSsimulationFastPointsV0()
+{
+  //constructor
+  fSx = new AliITSstatistics(2);
+  fSz = new AliITSstatistics(2);
+}
+
+//----------------------------------------------------------
+AliITSsimulationFastPointsV0::~AliITSsimulationFastPointsV0()
+{
+  //destructor
+  delete fSx;
+  delete fSz;
+
+}
+
+//-------------------------------------------------------------
+void AliITSsimulationFastPointsV0::CreateFastRecPoints(AliITSmodule *mod,Int_t module,TRandom *rndm){
+  // Fast points simulator for all of the ITS.
+  Int_t   nhit,h,trk,ifirst;
+  Float_t x,y,z,t,e;// local coordinate (cm) and time of flight, and dedx.
+  Float_t x1,y1,z1;
+  AliITShit *hit;
+
+  fSx->Reset(); // Start out with things clearly zeroed
+  fSz->Reset(); // Start out with things clearly zeroed
+  e = 0.; // Start out with things clearly zeroed
+  Double_t weight=1.;
+  nhit = mod->GetNhits();
+  ifirst = 1;
+  for(h=0;hGetHit(h);
+    hit->GetPositionL(x,y,z,t);
+    if(ifirst) {x1=x;y1=y;z1=z;}
+    e += hit->GetIonization();
+    trk = hit->GetTrack();
+    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 AliITSsimulationFastPointsV0::AddSPD(Float_t &e,
+					 AliITSmodule *mod,Int_t trackNumber){
+  const Float_t kmicronTocm = 1.0e-4;
+  //  const Float_t kdEdXtoQ = ;
+  const Float_t kRMSx = 12.0*kmicronTocm; // microns->cm ITS TDR Table 1.3
+  const Float_t kRMSz = 70.0*kmicronTocm; // microns->cm ITS TDR Table 1.3
+  Float_t a1,a2; // general float.
+  AliITSRecPoint rpSPD;
+
+  rpSPD.fTracks[0]=trackNumber;
+  rpSPD.fTracks[1]=0;
+  rpSPD.fTracks[2]=0;
+  rpSPD.SetX(fSx->GetMean());
+  rpSPD.SetZ(fSz->GetMean());
+  rpSPD.SetdEdX(0.0);
+  rpSPD.SetQ(1.0);
+  a1 = 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 = 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 AliITSsimulationFastPointsV0::AddSDD(Float_t &e,
+					 AliITSmodule *mod,Int_t trackNumber){
+
+  const Float_t kmicronTocm = 1.0e-4;
+  const Float_t kdEdXtoQ = 2.778e+8; 
+  const Float_t kRMSx = 38.0*kmicronTocm; // microns->cm ITS TDR Table 1.3
+  const Float_t kRMSz = 28.0*kmicronTocm; // microns->cm ITS TDR Table 1.3
+  Float_t a1,a2; // general float.
+  AliITSRecPoint rpSDD;
+
+  rpSDD.fTracks[0]=trackNumber;
+  rpSDD.fTracks[1]=0;
+  rpSDD.fTracks[2]=0;
+  rpSDD.SetX(fSx->GetMean());
+  rpSDD.SetZ(fSz->GetMean());
+  rpSDD.SetdEdX(e);
+  rpSDD.SetQ(kdEdXtoQ*e);
+  a1 = 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 = 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 AliITSsimulationFastPointsV0::AddSSD(Float_t &e,
+					 AliITSmodule *mod,Int_t trackNumber){
+
+  const Float_t kmicronTocm = 1.0e-4;
+  const Float_t kdEdXtoQ = 2.778e+8;
+  const Float_t kRMSx = 20.0*kmicronTocm;  // microns->cm ITS TDR Table 1.3
+  const Float_t kRMSz = 830.0*kmicronTocm; // microns->cm ITS TDR Table 1.3
+  Float_t a1,a2; // general float.
+  AliITSRecPoint rpSSD;
+
+  rpSSD.fTracks[0]=trackNumber;
+  rpSSD.fTracks[1]=0;
+  rpSSD.fTracks[2]=0;
+  rpSSD.SetX(fSx->GetMean());
+  rpSSD.SetZ(fSz->GetMean());
+  rpSSD.SetdEdX(e);
+  rpSSD.SetQ(kdEdXtoQ*e);
+  a1 = 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 = 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/AliITSsimulationFastPointsV0.h b/ITS/AliITSsimulationFastPointsV0.h
new file mode 100644
index 00000000000..a6c4acbb7d0
--- /dev/null
+++ b/ITS/AliITSsimulationFastPointsV0.h
@@ -0,0 +1,31 @@
+#ifndef ALIITSSIMULATIONFASTPOINTSV0_H
+#define ALIITSSIMULATIONFASTPOINTSV0_H
+
+#include "AliITSsimulation.h"
+
+class AliITSmodule;
+class AliITSstatistics;
+class TRandom;
+
+class AliITSsimulationFastPointsV0 : public AliITSsimulation
+{
+
+public:
+  AliITSsimulationFastPointsV0(); // default constructor
+  virtual ~AliITSsimulationFastPointsV0(); 
+  void CreateFastRecPoints(AliITSmodule *mod,Int_t module,TRandom *rndm);
+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(AliITSsimulationFastPointsV0,1) // Fast point simulator.
+
+};
+
+#endif
diff --git a/ITS/AliITSsimulationSDD.cxx b/ITS/AliITSsimulationSDD.cxx
index b83b97be5ef..34a0844936f 100644
--- a/ITS/AliITSsimulationSDD.cxx
+++ b/ITS/AliITSsimulationSDD.cxx
@@ -19,15 +19,15 @@
 #include 
 #include 
 
-
-
 #include "AliRun.h"
-#include "AliITSetfSDD.h"
+#include "AliITS.h"
+#include "AliITSMapA1.h"
+#include "AliITSMapA2.h"
 #include "AliITSsimulationSDD.h"
+#include "AliITSetfSDD.h"
+#include "AliITSRawData.h"
 #include "AliITSHuffman.h"
 
-const Int_t kMaxNeighbours = 4;
-
 ClassImp(AliITSsimulationSDD)
 ////////////////////////////////////////////////////////////////////////
 // Version: 0
@@ -50,7 +50,7 @@ ClassImp(AliITSsimulationSDD)
 //_____________________________________________________________________________
 
 Int_t power(Int_t b, Int_t e) {
-  // copute b to the e power, where bothe b and e are Int_ts.
+  // compute b to the e power, where both b and e are Int_ts.
   Int_t power = 1,i;
   for(i=0; iParamOptions(opt1,opt2);
       fParam=opt2;
       char *same = strstr(opt1,"same");
@@ -199,15 +203,15 @@ AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
       }
       
       //
-      Option_t *opt=fResponse->ZeroSuppOption();
+      const char *kopt=fResponse->ZeroSuppOption();
         if (strstr(fParam,"file") ) {
 	  fD.Set(fNofMaps);
 	  fT1.Set(fNofMaps);
-          if (strstr(opt,"2D")) {
+          if (strstr(kopt,"2D")) {
 	    fT2.Set(fNofMaps);
             fTol.Set(0);
             Init2D();       // desactivate if param change module by module
-          } else if(strstr(opt,"1D"))  {
+          } else if(strstr(kopt,"1D"))  {
             fT2.Set(2);
             fTol.Set(2);
             Init1D();      // desactivate if param change module by module
@@ -222,7 +226,7 @@ AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
 
 
 	Bool_t write=fResponse->OutputOption();
-	if(write && strstr(opt,"2D")) MakeTreeB();
+	if(write && strstr(kopt,"2D")) MakeTreeB();
 
         // call here if baseline does not change by module
         // ReadBaseline();
@@ -231,10 +235,10 @@ AliITSsimulationSDD::AliITSsimulationSDD(AliITSsegmentation *seg,
         Int_t size=fNofMaps*fMaxNofSamples;
 	fStream = new AliITSInStream(size); 
 	
-   fInZR = new Double_t [fMaxNofSamples];
-   fInZI = new Double_t [fMaxNofSamples];
-   fOutZR = new Double_t [fMaxNofSamples];
-   fOutZI = new Double_t [fMaxNofSamples];  
+	fInZR = new Double_t [fScaleSize*fMaxNofSamples];
+	fInZI = new Double_t [fScaleSize*fMaxNofSamples];
+	fOutZR = new Double_t [fScaleSize*fMaxNofSamples];
+	fOutZI = new Double_t [fScaleSize*fMaxNofSamples];  
 
 }
 
@@ -258,17 +262,11 @@ AliITSsimulationSDD::~AliITSsimulationSDD() {
   if (fHis) {
      fHis->Delete(); 
      delete fHis;     
-  }  
-  
-   delete [] fInZR;
-   delete [] fInZI;	
-	delete [] fOutZR;
-	delete [] fOutZI;
-	
-	delete  fInZR;
-   delete  fInZI;  
-	delete  fOutZR;
-	delete  fOutZI;				 
+  }                
+  if(fInZR) delete [] fInZR;
+  if(fInZI) delete [] fInZI;	
+  if(fOutZR) delete [] fOutZR;
+  if(fOutZI) delete [] fOutZI;
 }
 //_____________________________________________________________________________
 
@@ -287,11 +285,11 @@ void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
     TObjArray *list=new TObjArray;
     static TClonesArray *padr=0;
     if(!padr) padr=new TClonesArray("TVector",1000);
-    Int_t arg[5] = {0,0,0,0,0}; 
+    Int_t arg[6] = {0,0,0,0,0,0}; 
     fHitMap1->SetArray(list);
 
 
-    Int_t NofAnodes=fNofMaps/2;
+    Int_t nofAnodes=fNofMaps/2;
 
     Float_t sddLength = fSegmentation->Dx();
     Float_t sddWidth = fSegmentation->Dz();
@@ -308,30 +306,40 @@ void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
     // Fill detector maps with GEANT hits
     // loop over hits in the module
 
-    const Float_t kconv=1000000.;  // GeV->KeV
+    const Float_t kconv=1.0e+6;  // GeV->KeV
     Int_t ii;
     for(ii=0; iiAt(ii);
-	Int_t hitDetector = hit->GetDetector();
 	Float_t xL[3];
+	hit = (AliITShit*) fHits->At(ii);
 	hit->GetPositionL(xL[0],xL[1],xL[2]);
-	//  cout << "hit local coordinates: " << xL[0] << "," << xL[1] << "," << xL[2] << endl;
+	Int_t hitDetector = hit->GetDetector();
+
 	// 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();
+	if(depEnergy != 0.) continue;
+
+	ii++;
+	Float_t xL1[3];
+	hit1 = (AliITShit*) fHits->At(ii);
+	hit1->GetPositionL(xL1[0],xL1[1],xL1[2]);
+	avpath = xL1[0];
+	avanod = xL1[2];
+	depEnergy = kconv*hit1->GetIonization();
+	
+	// scale path to simulate a perpendicular track
+	if (fFlag) {
+	  Float_t lC[3];
+	  hit->GetPositionL(lC[0],lC[1],lC[2]);
+	  Float_t lC1[3];
+	  hit1->GetPositionL(lC1[0],lC1[1],lC1[2]);
+	  Float_t pathInSDD = TMath::Sqrt((lC[0]-lC1[0])*(lC[0]-lC1[0])+(lC[1]-lC1[1])*(lC[1]-lC1[1])+(lC[2]-lC1[2])*(lC[2]-lC1[2]));
+	  depEnergy *= (0.03/pathInSDD);
 	}
+
 	Float_t avDrft = xL[0]+avpath;
 	Float_t avAnode = xL[2]+avanod;
 
@@ -339,7 +347,6 @@ void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
 	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;
@@ -354,112 +361,116 @@ void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
 	 
 	//   Drift Time
 	Float_t driftTime = driftPath/driftSpeed;
-	Int_t timeSample = (Int_t) (driftTime/timeStep + 1);
-	if(timeSample > fMaxNofSamples) {
+	Int_t timeSample = (Int_t) (fScaleSize*driftTime/timeStep + 1);
+	if(timeSample > fScaleSize*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.) 
+	Float_t xAnode = 10000.*(avAnode)/anodePitch + nofAnodes/2;  // +1?
+	if((xAnode+1)*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) {
+	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);  
+	// work with the idtrack=entry number in the TreeH for the moment
+	Int_t idhit,idtrack;
+	mod->GetHitTrackAndHitIndex(ii,idtrack,idhit);    
+	//Int_t idtrack=mod->GetHitTrackIndex(ii);  
         // or store straight away the particle position in the array
 	// of particles : 
-        Int_t idtrack = hit->GetTrack();
+        Int_t itrack = hit->GetTrack();
 
 	//  Signal 2d Shape
-	Double_t qRef = (Double_t)fResponse->Qref();
-	Double_t diffCoeff = (Double_t)fResponse->DiffCoeff();
+	Float_t diffCoeff, s0;
+	fResponse->DiffCoeff(diffCoeff,s0);
     
-	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;
+	Double_t sigma2A = 2.*diffCoeff*driftTime+s0*s0;
+	Double_t sigmaA  = TMath::Sqrt(sigma2A);
+	Double_t sigmaT  = sigmaA/driftSpeed;
     
 	// Peak amplitude in nanoAmpere
 	Double_t eVpairs = 3.6;
-	Double_t amplitude = 160.*depEnergy/(timeStep*eVpairs*2.*acos(-1.)*sigmaT*TMath::Sqrt(sigma2A));
+	Double_t amplitude = fScaleSize*160.*depEnergy/(timeStep*eVpairs*2.*acos(-1.)*sigmaT*sigmaA);
     
+	Float_t nsigma=fResponse->NSigmaIntegration();
 	// Spread the charge 
 	// Pixel index
 	Int_t ja = iAnode;
 	Int_t jt = timeSample;
 	// Sub-pixel index
-	Int_t nsplit = 8;
+	Int_t nsplit = 4; // hard-wired
 	nsplit = (nsplit+1)/2*2;
 	// Sub-pixel size
-	Double_t aStep = anodePitch/nsplit;
-	Double_t tStep = timeStep/nsplit;
+	Double_t aStep = anodePitch/(nsplit*fScaleSize);
+	Double_t tStep = timeStep/(nsplit*fScaleSize);
 	// 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;
+	Int_t anodeWindow = (Int_t) (fScaleSize*nsigma*sigmaA/anodePitch + 1);
+	Int_t timeWindow = (Int_t) (fScaleSize*nsigma*sigmaT/timeStep + 1);
+	Int_t jamin = (ja - anodeWindow/2 - 1)*fScaleSize*nsplit + 1;
+	Int_t jamax = (ja + anodeWindow/2)*fScaleSize*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(jamax > fScaleSize*nofAnodes*nsplit) jamax = fScaleSize*nofAnodes*nsplit;
+	Int_t jtmin = (jt - timeWindow*3 - 1)*nsplit + 1; //hard-wired
+	Int_t jtmax = (jt + timeWindow*3)*nsplit; //hard-wired
 	if(jtmin <= 0) jtmin = 1;
-	if(jtmax > fMaxNofSamples*nsplit) jtmax = fMaxNofSamples*nsplit;
+	if(jtmax > fScaleSize*fMaxNofSamples*nsplit) jtmax = fScaleSize*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;
+	  Int_t ia = (ka-1)/(fScaleSize*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;
+	  if(ia > nofAnodes) ia = nofAnodes;
+	  Double_t aExpo = (aStep*(ka-0.5)-xAnode*anodePitch)/sigmaA;
+	  Double_t anodeAmplitude = rlAnode - 0.5*aExpo*aExpo;
 	  // Protect against overflows
 	  if(anodeAmplitude > -87.3)
 	    anodeAmplitude = exp(anodeAmplitude);
 	  else
 	    anodeAmplitude = 0;
+	  Int_t index = ((detector+1)%2)*nofAnodes+ia-1;  // index starts from 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;
+	      Int_t it = (kt-1)/nsplit+1;  // it starts from 1
 	      if(it<=0) { cout << "Warning: it < 1: " << endl; continue; } 
-	      if(it>fMaxNofSamples) it = fMaxNofSamples;
-	      Double_t tExpo = (tStep*(kt)-driftTime)/sigmaT;
+	      if(it>fScaleSize*fMaxNofSamples) it = fScaleSize*fMaxNofSamples;
+	      Double_t tExpo = (tStep*(kt-0.5)-driftTime)/sigmaT;
 	      Double_t timeAmplitude = rlTime - 0.5*tExpo*tExpo;
 	      // Protect against overflows
-	      if(timeAmplitude > -87.3)
+	      if(timeAmplitude > -87.3){
 		timeAmplitude = exp(timeAmplitude);
-	      else
+	      } 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;
+	      arg[2]=itrack;
+	      arg[3]=idhit;
 	      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
+  Int_t nentries=list->GetEntriesFast();
   if (nentries) {
     ChargeToSignal(); 
 
-    Option_t *opt=fResponse->ZeroSuppOption();
-    ZeroSuppression(opt);
+    const char *kopt=fResponse->ZeroSuppOption();
+    ZeroSuppression(kopt);
   } 
 
   // clean memory
@@ -482,37 +493,42 @@ void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
   // Returns the list of "fired" cells.
 
                     Int_t index=arg[0];
-                    Int_t it=arg[1];
+                    Int_t ik=arg[1];
                     Int_t idtrack=arg[2];
-                    Int_t counter=arg[3];
-                    Int_t countadr=arg[4];
+                    Int_t idhit=arg[3];
+                    Int_t counter=arg[4];
+                    Int_t countadr=arg[5];
                    
-                    Int_t digits[3];
+                    Double_t charge=timeAmplitude;
+		    charge += fHitMap2->GetSignal(index,ik-1);
+		    fHitMap2->SetHit(index, ik-1, charge);
 
+                    Int_t digits[3];
+		    Int_t it=(Int_t)((ik-1)/fScaleSize);
+		    
 		    digits[0]=index;
-		    digits[1]=it-1;
+		    digits[1]=it;
 		    digits[2]=(Int_t)timeAmplitude;
                     Float_t phys;
 		    if (idtrack >= 0) phys=(Float_t)timeAmplitude;
 		    else phys=0;
                    
-                    Double_t charge=timeAmplitude;
+		    Double_t cellcharge=0.;
 		    AliITSTransientDigit* pdigit;
 		    // build the list of fired cells and update the info
-		    if (!fHitMap1->TestHit(index, it-1)) {
+		    if (!fHitMap1->TestHit(index, it)) {
 		      
-		        new((*padr)[countadr++]) TVector(2);
+		        new((*padr)[countadr++]) TVector(3);
 			TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
 			trinfo(0)=(Float_t)idtrack;
-			trinfo(1)=(Float_t)timeAmplitude;
+			trinfo(1)=(Float_t)idhit;
+			trinfo(2)=(Float_t)timeAmplitude;
 
 			list->AddAtAndExpand(
 			    new AliITSTransientDigit(phys,digits),counter);
 			
-			fHitMap1->SetHit(index, it-1, counter);
-			fHitMap2->SetHit(index, it-1, charge);
+			fHitMap1->SetHit(index, it, counter);
 			counter++;
-
 			pdigit=(AliITSTransientDigit*)list->
                                                       At(list->GetLast());
 			// list of tracks
@@ -521,11 +537,12 @@ void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
 
 		    } else {
 			pdigit=
-                         (AliITSTransientDigit*) fHitMap1->GetHit(index, it-1);
-                        charge += fHitMap2->GetSignal(index,it-1);
-			fHitMap2->SetHit(index, it-1, charge);
+                         (AliITSTransientDigit*) fHitMap1->GetHit(index, it);
+			for(Int_t kk=0;kkGetSignal(index,fScaleSize*it+kk);
+			}
 			// update charge
-			(*pdigit).fSignal=(Int_t)charge;
+			(*pdigit).fSignal=(Int_t)cellcharge;
 			(*pdigit).fPhysics+=phys;			
 			// update list of tracks
 			TObjArray* trlist=(TObjArray*)pdigit->TrackList();
@@ -533,36 +550,40 @@ void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
 			TVector *ptrkp=(TVector*)trlist->At(lastentry);
 			TVector &trinfo=*ptrkp;
 			Int_t lasttrack=Int_t(trinfo(0));
-			Float_t lastcharge=(trinfo(1));
+			Int_t lasthit=Int_t(trinfo(1));
+			Float_t lastcharge=(trinfo(2));
 			
  			if (lasttrack==idtrack ) {
 			    lastcharge+=(Float_t)timeAmplitude;
 			    trlist->RemoveAt(lastentry);
 			    trinfo(0)=lasttrack;
-			    trinfo(1)=lastcharge;
+			    trinfo(1)=lasthit; // or idhit
+			    trinfo(2)=lastcharge;
 			    trlist->AddAt(&trinfo,lastentry);
 			} else {
 			  
-		            new((*padr)[countadr++]) TVector(2);
+		            new((*padr)[countadr++]) TVector(3);
 			    TVector &trinfo=*((TVector*) (*padr)[countadr-1]);
 			    trinfo(0)=(Float_t)idtrack;
-			    trinfo(1)=(Float_t)timeAmplitude;
+			    trinfo(1)=(Float_t)idhit;
+			    trinfo(2)=(Float_t)timeAmplitude;
 			  
 			    trlist->Add(&trinfo);
 			}
 
 #ifdef print
 			// check the track list - debugging
-                        Int_t trk[50];
-                        Float_t chtrk[50];  
+                        Int_t trk[20], htrk[20];
+                        Float_t chtrk[20];  
 			Int_t nptracks=trlist->GetEntriesFast();
 			if (nptracks > 2) {
                             Int_t tr;
-			    for(tr=0;trAt(tr);
 				TVector &pptrk=*pptrkp;
 				trk[tr]=Int_t(pptrk(0));
-				chtrk[tr]=(pptrk(1));
+				htrk[tr]=Int_t(pptrk(1));
+				chtrk[tr]=(pptrk(2));
                                 printf("nptracks %d \n",nptracks);
 				// set printings
 			    }
@@ -570,8 +591,8 @@ void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
 #endif
 		    } //  end if pdigit
 
-                    arg[3]=counter;
-                    arg[4]=countadr;
+                    arg[4]=counter;
+                    arg[5]=countadr;
 
 
 }
@@ -584,10 +605,10 @@ void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
     // tag with -1 signals coming from background tracks
     // tag with -2 signals coming from pure electronic noise
 
-    Int_t digits[3], tracks[3];
+    Int_t digits[3], tracks[3], hits[3];
     Float_t phys, charges[3];
 
-    Int_t trk[20];
+    Int_t trk[20], htrk[20];
     Float_t chtrk[20];  
 
     signal=Convert8to10(signal); // set a flag in case non-ZS are 10-bit
@@ -595,19 +616,17 @@ void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
     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++) {
+        for (k=0;k<3;k++) {
 	  tracks[k]=-2;
           charges[k]=0;
+          hits[k]=0;
 	}
-        fITS->AddDigit(1,phys,digits,tracks,charges); 
+        fITS->AddSimDigit(1,phys,digits,tracks,hits,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();
 
@@ -616,33 +635,36 @@ void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
 	 nptracks=20;
       }
       Int_t tr;
-      for(tr=0;trAt(tr));
 	  trk[tr]=Int_t(pp(0));
-	  chtrk[tr]=(pp(1));
+	  htrk[tr]=Int_t(pp(1));
+	  chtrk[tr]=(pp(2));
       }
       if (nptracks > 1) {
-	  //printf("AddDigit: nptracks %d\n",nptracks);
-	  SortTracks(trk,chtrk,nptracks);
+	  SortTracks(trk,chtrk,htrk,nptracks);
       }
       Int_t i;
       if (nptracks < 3 ) {
-	 for(i=0; iAddDigit(1,phys,digits,tracks,charges); 
+      fITS->AddSimDigit(1,phys,digits,tracks,hits,charges); 
  
     }
 
@@ -650,7 +672,7 @@ void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
 
 //____________________________________________
 
-void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,Int_t ntr){
+void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,Int_t *hits,Int_t ntr){
   //
   // Sort the list of tracks contributing to a given digit
   // Only the 3 most significant tracks are acctually sorted
@@ -666,6 +688,7 @@ void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,Int_t ntr){
   Int_t idx[3] = {-3,-3,-3};
   Float_t jch[3] = {-3,-3,-3};
   Int_t jtr[3] = {-3,-3,-3};
+  Int_t jhit[3] = {-3,-3,-3};
   Int_t i,j,imax;
   
   if (ntr<3) imax=ntr;
@@ -689,6 +712,7 @@ void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,Int_t ntr){
       idx[i]=jmax;
       jch[i]=charges[jmax]; 
       jtr[i]=tracks[jmax]; 
+      jhit[i]=hits[jmax]; 
     }
     
   } 
@@ -696,10 +720,12 @@ void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,Int_t ntr){
   for(i=0;i<3;i++){
     if (jtr[i] == -3) {
          charges[i]=0;
-         tracks[i]=0;
+         tracks[i]=-3;
+         hits[i]=-1;
     } else {
          charges[i]=jch[i];
          tracks[i]=jtr[i];
+         hits[i]=jtr[i];
     }
   }
 
@@ -708,20 +734,13 @@ void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,Int_t ntr){
 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;
+  Float_t topValue = fResponse->MagicValue();
+  Float_t norm = maxadc/topValue;
 
 
-  Option_t *opt1, *opt2;
+  char opt1[20], opt2[20];
   fResponse->ParamOptions(opt1,opt2);
   char *read = strstr(opt1,"file");
 
@@ -737,56 +756,64 @@ void AliITSsimulationSDD::ChargeToSignal() {
   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);
+  TRandom *random = new TRandom(); 
+  Int_t i,k,kk; 
+  for (i=0;i<=fNofMaps;i++) {
+    if  (read && i 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);
-	   fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
-	   fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
-	   if(i+1 < fNofMaps) fInZR[k] = fHitMap2->GetSignal(i+1,k);
+	    Float_t newcont = 0.;
+	    Float_t maxcont = 0.;
+	    Int_t it=(Int_t)(k/fScaleSize);
+            if (k%fScaleSize == 0) {
+	      for(kk=0;kk maxcont) maxcont = newcont;
+	      }
+	      newcont = maxcont;
+	      // analog to digital ?
+	      Double_t signal = newcont*norm;
+	      if (signal >= maxadc) signal = maxadc -1;
+	      // back to analog: ?
+	      signal /=norm;
+	      fHitMap2->SetHit(i-1,it,signal);
+	    }
+	    Double_t rw = fElectronics->GetTraFunReal(k);
+	    Double_t iw = fElectronics->GetTraFunImag(k);
+	    fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
+	    fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
+	    if(i+1 < fNofMaps) fInZR[k] = fHitMap2->GetSignal(i+1,k);
 	}
-
+	
         if (first) {
-             fInZR[k] = fHitMap2->GetSignal(i,k);
-	 }
+	  fInZR[k] = fHitMap2->GetSignal(i,k);
+	}
         fInZI[k] = 0.;
         // add baseline and noise 
         contrib = baseline + noise*random->Gaus();
         fInZR[k] += contrib;
-
+	
     } // loop over time
     
     if (first) {
-         FastFourierTransform(fElectronics,&fInZR[0],&fInZI[0],1);
-	 for(k=0; kGetTraFunReal(k);
-	     Double_t iw = fElectronics->GetTraFunImag(k);
-	     fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
-	     fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
-	     fInZR[k] = fHitMap2->GetSignal(i+1,k);
-	     fInZI[k] = 0.;
-	     // add baseline and noise 
-	     contrib = baseline + noise*random->Gaus();
-	     fInZR[k] += contrib;
-	  }
+      FastFourierTransform(fElectronics,&fInZR[0],&fInZI[0],1);
+      for (k=0; kGetTraFunReal(k);
+	Double_t iw = fElectronics->GetTraFunImag(k);
+	fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw;
+	fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw;
+	fInZR[k] = fHitMap2->GetSignal(i+1,k);
+	fInZI[k] = 0.;
+	// add baseline and noise 
+	contrib = baseline + noise*random->Gaus();
+	fInZR[k] += contrib;
+      }
     }
-    FastFourierTransform(fElectronics,&fOutZR[0],&fOutZI[0],-1);
+    if(iGiveCompressParam(cp);
-   for(i=0; i<2; i++) {
+   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]);
-       */
    }
 }
 
@@ -859,10 +884,10 @@ void AliITSsimulationSDD::ReadBaseline(){
 
     Int_t na,pos;
     Float_t bl,n;
-    const char *kinput, *base,*kparam;
+    char input[100], base[100], param[100];
     char *filtmp;
 
-    fResponse->Filenames(kinput,base,kparam);
+    fResponse->Filenames(input,base,param);
     fFileName=base;
 //
     filtmp = gSystem->ExpandPathName(fFileName.Data());
@@ -872,7 +897,6 @@ void AliITSsimulationSDD::ReadBaseline(){
 
     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);
@@ -890,8 +914,6 @@ void AliITSsimulationSDD::ReadBaseline(){
     
     fclose(bline);
     delete [] filtmp;
-
-                        
 } 
 
 //____________________________________________
@@ -939,7 +961,7 @@ AliITSMap*   AliITSsimulationSDD::HitMap(Int_t i){
 
 
 //____________________________________________
-void AliITSsimulationSDD::ZeroSuppression(Option_t *option) {
+void AliITSsimulationSDD::ZeroSuppression(const char *option) {
   // perform the zero suppresion
   if (strstr(option,"2D")) {
     //Init2D();              // activate if param change module by module
@@ -969,15 +991,15 @@ void AliITSsimulationSDD::Init2D(){
     Int_t na,pos,tempTh;
     Float_t mu,sigma;
     Float_t *savemu = new Float_t [fNofMaps];
-	 Float_t *savesigma = new Float_t [fNofMaps];
-    const char *kinput,*kbasel,*kpar;
+    Float_t *savesigma = new Float_t [fNofMaps];
+    char input[100],basel[100],par[100];
     char *filtmp;
 
 
     Int_t minval = fResponse->MinVal();
 
-    fResponse->Filenames(kinput,kbasel,kpar);
-    fFileName=kpar;
+    fResponse->Filenames(input,basel,par);
+    fFileName=par;
 
 //
     filtmp = gSystem->ExpandPathName(fFileName.Data());
@@ -1015,13 +1037,9 @@ void AliITSsimulationSDD::Init2D(){
     fclose(param);
     delete [] filtmp;
     delete [] savemu;
-	 delete [] savesigma;
-	 delete savemu;
-	 delete savesigma;
-	 
-
-
+    delete [] savesigma;
 } 
+
 //____________________________________________
 void AliITSsimulationSDD::Compress2D(){
   //
@@ -1029,21 +1047,19 @@ void AliITSsimulationSDD::Compress2D(){
   // 
   //
 
-  //printf("Compress2D!\n");
-
     Int_t db,tl,th;  
     Int_t minval = fResponse->MinVal();
     Bool_t write=fResponse->OutputOption();   
 
     Int_t nz, nl, nh, low, i, j; 
 
-    for(i=0; iGetSignal(i,j));
 	    signal -= db; // if baseline eq. is done here
             if (signal <= 0) {nz++; continue;}
@@ -1051,12 +1067,10 @@ void AliITSsimulationSDD::Compress2D(){
             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];
@@ -1082,14 +1096,16 @@ void  AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal,
 //
 //  check the online zero-suppression conditions
 //  
+    const Int_t maxNeighbours = 4;
+
     Int_t nn;
     Int_t dbx,tlx,thx;  
-    Int_t Xlist[kMaxNeighbours], Ylist[kMaxNeighbours];
-    fSegmentation->Neighbours(i,j,&nn,Xlist,Ylist);
+    Int_t xList[maxNeighbours], yList[maxNeighbours];
+    fSegmentation->Neighbours(i,j,&nn,xList,yList);
     Int_t in,ix,iy;
-    for(in=0; inTestHit(ix,iy)==kUnused) {
 	   CompressionParam(ix,dbx,tlx,thx);
            Int_t qn = (Int_t)(fHitMap2->GetSignal(ix,iy));
@@ -1101,11 +1117,9 @@ void  AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal,
               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);
@@ -1127,15 +1141,15 @@ void AliITSsimulationSDD::Init1D(){
 
     Int_t na,pos,tempTh;
     Float_t mu,sigma;
-	 Float_t *savemu = new Float_t [fNofMaps];
-	 Float_t *savesigma = new Float_t [fNofMaps];
-    const char *kinput,*kbasel,*kpar;
+    Float_t *savemu = new Float_t [fNofMaps];
+    Float_t *savesigma = new Float_t [fNofMaps];
+    char input[100],basel[100],par[100];
     char *filtmp;
 
 
     Int_t minval = fResponse->MinVal();
-    fResponse->Filenames(kinput,kbasel,kpar);
-    fFileName=kpar;
+    fResponse->Filenames(input,basel,par);
+    fFileName=par;
 
 //  set first the disable and tol param
     SetCompressParam();
@@ -1172,9 +1186,9 @@ void AliITSsimulationSDD::Init1D(){
     fclose(param);
     delete [] filtmp;
     delete [] savemu;
-	 delete [] savesigma;
-	 delete savemu;
-	 delete savesigma;
+    delete [] savesigma;
+
+
 
 }
  
@@ -1183,19 +1197,19 @@ 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++) {
+    Int_t last=0;
+    Int_t k,i,j;
+    for (k=1; k<=2; k++) {
          tol = Tolerance(k-1);
          dis = Disable(k-1);  
-	 for(i=0; iGetSignal(k*i,j));
                  signal -= decr;  // if baseline eq.
 		 signal = Convert10to8(signal);
@@ -1239,18 +1253,18 @@ void AliITSsimulationSDD::Compress1D(){
     // open file and write out the stream of diff's
    
     static Bool_t open=kTRUE;
-    static TFile *OutFile;
+    static TFile *outFile;
     Bool_t write = fResponse->OutputOption();
  
     if (write ) {
 	if(open) {
 	    SetFileName("stream.root");
 	    cout<<"filename "<cd();
+	outFile->cd();
         fStream->Write();
     }  // endif write	
 
@@ -1270,10 +1284,10 @@ void AliITSsimulationSDD::Compress1D(){
 void AliITSsimulationSDD::StoreAllDigits(){
   // if non-zero-suppressed data
 
-    Int_t digits[3],i,j;
+    Int_t i, j, digits[3];
 
-    for(i=0; iGetSignal(i,j));
 	     signal = Convert10to8(signal);
 	     signal = Convert8to10(signal); // ?
@@ -1290,7 +1304,7 @@ void AliITSsimulationSDD::CreateHistograms(){
   // Creates histograms of maps for debugging
 
       Int_t i;
-      for(i=0;iReset();
     }
 
@@ -1352,9 +1366,9 @@ Float_t AliITSsimulationSDD::GetNoise(Float_t threshold) {
 
   TH1F *noisehist = new TH1F("noisehist","noise",100,0.,threshold);
   Int_t i,k;
-  for(i=0;iGetNbinsX();
-    for(k=0;kGetBinContent(k+1);
       if (content < threshold) noisehist->Fill(content);
     }
@@ -1369,53 +1383,3 @@ Float_t AliITSsimulationSDD::GetNoise(Float_t threshold) {
   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
index 86e04e7ff3b..8ea42ca0c13 100644
--- a/ITS/AliITSsimulationSDD.h
+++ b/ITS/AliITSsimulationSDD.h
@@ -9,16 +9,17 @@
 #include 
 #include 
 
-
-#include "AliITSMap.h"
 #include "AliITSsimulation.h"
-#include "AliITSRawData.h"
 
 //___________________________________________________
 
 
-
+class AliITS;
+class AliITSMap;
+class AliITSMapA1;
+class AliITSMapA2;
 class AliITSetfSDD;
+class AliITSInStream;
 
 //___________________________________________________
 
@@ -35,6 +36,12 @@ public:
   // get the address of the array mapping the signal or pointers to arrays
   virtual AliITSMap*  HitMap(Int_t i);
 
+  // set the scale size factor for the smples in FFT
+  virtual void SetScaleFourier(Int_t scale=4) {fScaleSize=scale;}
+  Int_t ScaleFourier() {return fScaleSize;}
+  // set perpendicular tracks flag
+  virtual void SetPerpendTracksFlag(Bool_t flag=1) {fFlag=1;}
+  Bool_t PerpendTracksFlag() {return fFlag;} 
   // set compression parameters for 2D or 1D via response functions
   void SetCompressParam();
   // retrieve compression parameters for 2D or 1D
@@ -43,7 +50,7 @@ public:
 
   virtual Int_t Convert10to8(Int_t signal);
   virtual Int_t Convert8to10(Int_t signal);
-  virtual void ZeroSuppression(Option_t *opt);
+  virtual void ZeroSuppression(const char *opt);
   virtual void Init2D();
   virtual void Compress2D();
   virtual void Init1D();
@@ -60,21 +67,21 @@ public:
   // 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];}
+  // Set the output file name - for 1D encoding 
   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 SortTracks(Int_t *tracks,Float_t *charges,Int_t *hits,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();
+  // Get the pointer to the array of histograms
   TObjArray*  GetHistArray() {return fHis;}
 
-  // create a separate tree for background monitoring (2D) -easy to do
+  // create a separate tree for background monitoring (2D) 
   virtual  void  MakeTreeB(Option_t *option="B") 
       { fTreeB = new TNtuple("ntuple","2D backgr","nz:nl:nh:low:anode");}
   void           GetTreeB(Int_t) { }
@@ -100,21 +107,27 @@ private:
   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
+  TNtuple            *fTreeB;        // Background info tree for 2D
+  TString             fParam;        // Compresion algorithm options
+  TString             fFileName;     // File name for possible options above
 
+  Bool_t fFlag;         // Flag to simulate perpendicular tracks
   Int_t fNofMaps;       // Number of anodes used ( 1 - 2*nanodes per wing )
   Int_t fMaxNofSamples; // Number of time samples
+  Int_t fScaleSize;     // scale size factor for the samples in FFT
   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
 
-  Double_t            *fInZR; // input of the real part of FFT
-  Double_t            *fInZI; // input of the imaginary part of FFT
-  Double_t            *fOutZR; // output of the real part of FFT
-  Double_t            *fOutZI; // output of the imaginary part of FFT
+  Double_t            *fInZR;  // ! [fScaleSize*fMaxNofSamples]  
+                               // input of the real part of FFT
+  Double_t            *fInZI;  // ! [fScaleSize*fMaxNofSamples] 
+                               // input of the imaginary part of FFT
+  Double_t            *fOutZR; // ! [fScaleSize*fMaxNofSamples] 
+                               // output of the real part of FFT
+  Double_t            *fOutZI; // ! [fScaleSize*fMaxNofSamples] 
+                               // output of the imaginary part of FFT
 
   ClassDef(AliITSsimulationSDD,1)  // Simulation of SDD clusters
     
diff --git a/ITS/AliITSsimulationSPD.cxx b/ITS/AliITSsimulationSPD.cxx
index af2d4af650d..2e4e7c6c6b7 100644
--- a/ITS/AliITSsimulationSPD.cxx
+++ b/ITS/AliITSsimulationSPD.cxx
@@ -1,12 +1,16 @@
 #include 
 #include 
 #include 
+#include 
+
+
 
 #include "AliRun.h"
-#include "AliITSMap.h"    // "AliITSMapA2.h"
+#include "AliITS.h"
+#include "AliITSMapA2.h" 
 #include "AliITSsimulationSPD.h"
-#include "AliITSsegmentation.h"
-#include "AliITSresponse.h"
+
+
 
 ClassImp(AliITSsimulationSPD)
 ////////////////////////////////////////////////////////////////////////
@@ -15,30 +19,33 @@ ClassImp(AliITSsimulationSPD)
 // December 20 1999
 //
 // AliITSsimulationSPD is the simulation of SPDs
-//
 //________________________________________________________________________
 
-AliITSsimulationSPD::AliITSsimulationSPD(){
+
+AliITSsimulationSPD::AliITSsimulationSPD()
+{
   // constructor
-  fResponse     = 0;
+  fResponse = 0;
   fSegmentation = 0;
-  fHis          = 0;
-  fNoise        = 0.;
-  fBaseline     = 0.;
+  fHis = 0;
+  fNoise=0.;
+  fBaseline=0.;
 }
+
+
 //_____________________________________________________________________________
 
 AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg, AliITSresponse *resp) {
-  // constructor
+  // standard constructor
+
       fResponse = resp;
       fSegmentation = seg;
 
       fResponse->GetNoiseParam(fNoise,fBaseline);
 
- 
       fMapA2 = new AliITSMapA2(fSegmentation);
-   
-      // 
+
+      //
       fNPixelsZ=fSegmentation->Npz();
       fNPixelsX=fSegmentation->Npx();
 
@@ -57,6 +64,7 @@ AliITSsimulationSPD::~AliITSsimulationSPD() {
   }                
 }
 
+
 //__________________________________________________________________________
 AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &source){
   //     Copy Constructor 
@@ -85,21 +93,26 @@ AliITSsimulationSPD&
   }
 //_____________________________________________________________________________
 
-void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy) {
+void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy)
+{
   // digitize module
-    const Float_t kEntoEl = 2.778e+8; // GeV->charge in electrons 
+
+    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 spdLength = fSegmentation->Dz();
     Float_t spdWidth = fSegmentation->Dx();
 
-    Float_t difCoef = fResponse->DiffCoeff();  
+    Float_t difCoef, dum; 
+    fResponse->DiffCoeff(difCoef,dum); 
 
     Float_t zPix0 = 1e+6;
     Float_t xPix0 = 1e+6;
     Float_t yPix0 = 1e+6;
-    Float_t yPrev = 1e+6;
+    Float_t yPrev = 1e+6;   
+    Float_t zP0 = 100.;
+    Float_t xP0 = 100.;
 
     Float_t zPitch = fSegmentation->Dpz(0);
     Float_t xPitch = fSegmentation->Dpx(0);
@@ -115,70 +128,57 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
 
   //  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 maxNDigits = fNPixelsX*fNPixelsZ + fNPixelsX ;; 
+    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;hitAt(hit);
-	layer = iHit->GetLayer();
+	Int_t layer = iHit->GetLayer();
+
 
 	// work with the idtrack=entry number in the TreeH
-	// Int_t idtrack=mod->GetHitTrackIndex(ii);  
+	Int_t idhit,idtrack;
+	mod->GetHitTrackAndHitIndex(hit,idtrack,idhit);    
+	//Int_t idtrack=mod->GetHitTrackIndex(hit);  
         // 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);
-	//}
+        Int_t itrack = iHit->GetTrack();
    
 	//  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
+	Float_t zPix = kconv*iHit->GetZL();
+	Float_t xPix = kconv*iHit->GetXL();
+	Float_t yPix = kconv*iHit->GetYL();
 
 	// Get track status
-	status = iHit->GetTrackStatus();      
-	if(status != 66 && status != 68) {
-	  printf("!!!!! no order status  %d\n",status);
-	}
+	Int_t status = iHit->GetTrackStatus();      
+      
+	// Check boundaries
+	if(TMath::Abs(zPix) > spdLength/2.) {
+	  printf("!! Zpix outside = %f\n",zPix);
+	  if(status == 66) zP0=100;
+	  continue;
+	} 
+
+
+	if (TMath::Abs(xPix) > spdWidth/2.) {
+	  printf("!! Xpix outside = %f\n",xPix);
+	  if (status == 66) xP0=100;
+	  continue;
+	}  
+
+	Float_t zP = (zPix + spdLength/2.)/1000.;  
+	Float_t xP = (xPix + spdWidth/2.)/1000.;  
 
-	trdown = 0;
+	Int_t trdown = 0;
 
 	// enter Si or after event in Si
 	if (status == 66 ) {  
@@ -189,14 +189,21 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
 	// enter Si only
 	if (layer == 1 && status == 66 && yPix > 71.) {     
              yPix0 = yPix;
+             zP0 = zP;
+             xP0 = xP;
 	}
 	// enter Si only
 	if (layer == 2 && status == 66 && yPix < -71.) {    
              yPix0 = yPix;
-	}
-	depEnergy = iHit->GetIonization();
+             zP0 = zP;
+             xP0 = xP;
+	}       
+	Float_t depEnergy = iHit->GetIonization();
 	// skip if the input point to Si       
-	if(depEnergy <= 0.) continue;  
+	if(depEnergy <= 0.) continue;        
+	// skip if the input point is outside of Si, but the next
+	// point is inside of Si
+	if(zP0 > 90 || xP0 > 90) continue; 
 	// if track returns to the opposite direction:
 	if (layer == 1 && yPix > yPrev) {
 	    yPix0 = yPrev;
@@ -205,7 +212,7 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
 	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
@@ -216,82 +223,85 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
 
 	//  ---------- 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
+	Float_t charge = depEnergy*kEnToEl;         // charge in e-
+	Float_t drPath = 0.;   
+	Float_t tang = 0.;
+	Float_t 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; 
+	Float_t projDif = sqrt(xdif*xdif + zdif*zdif);
+	Int_t ndZ = (Int_t)TMath::Abs(zdif/zPitch) + 1;
+	Int_t ndX = (Int_t)TMath::Abs(xdif/xPitch) + 1; 
 
 	// number of the steps along the track:
-	nsteps = ndZ;
+	Int_t 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) tang = ydif/projDif;
+	Float_t dCharge = charge/nsteps;       // charge in e- for one step
+	Float_t dZ = zdif/nsteps;
+	Float_t dX = xdif/nsteps;
 
 	if (TMath::Abs(projDif) < 5.0 ) {
-	   drPath = yDif*1.e-4;  
+	   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;
+	for (iZi = 1;iZi <= nsteps;iZi++) {
+            Float_t dZn = iZi*dZ;
+	    Float_t dXn = iZi*dX;
+	    Float_t zPixn = zPix0 + dZn;
+	    Float_t xPixn = xPix0 + dXn;
 
 	    if(TMath::Abs(projDif) >= 5.) {
-	      dProjn = sqrt(dZn*dZn+dXn*dXn);
+	      Float_t dProjn = sqrt(dZn*dZn+dXn*dXn);
 	      if(trdown == 0) {
-		drPath = dProjn*tAng*1.e-4; // drift path for iZi step in cm 
+		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;
+		Float_t 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);
+	    zPixn = (zPixn + spdLength/2.);  
+	    xPixn = (xPixn + spdWidth/2.);  
+            Int_t nZpix, nXpix;
+            fSegmentation->GetPadIxz(xPixn,zPixn,nXpix,nZpix);
 	    zPitch = fSegmentation->Dpz(nZpix);
+            fSegmentation->GetPadTxz(xPixn,zPixn);
 	    // set the window for the integration
-	    jzmin = 1;
-	    jzmax = 3; 
+	    Int_t jzmin = 1;  
+	    Int_t jzmax = 3; 
 	    if(nZpix == 1) jzmin =2;
 	    if(nZpix == fNPixelsZ) jzmax = 2; 
 
-	    jxmin = 1;  
-	    jxmax = 3; 
+	    Int_t jxmin = 1;  
+	    Int_t 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.;
+	    Float_t zpix = nZpix; 
+	    Float_t dZright = zPitch*(zpix - zPixn);
+	    Float_t dZleft = zPitch - dZright;
+
+	    Float_t xpix = nXpix; 
+	    Float_t dXright = xPitch*(xpix - xPixn);
+	    Float_t dXleft = xPitch - dXright;
+
+	    Float_t dZprev = 0.;
+	    Float_t dZnext = 0.;
+	    Float_t dXprev = 0.;
+	    Float_t dXnext = 0.;
 
 	    for(jz=jzmin; jz <=jzmax; jz++) {
 	        if(jz == 1) {
@@ -306,16 +316,15 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
 		  dZprev = dZright;
 		  dZnext = dZright + zPitch;
 		} 
-		// lz changes from 1 to the fNofPixels(270)
-		lz = nZpix + jz -2; 
+		// kz changes from 1 to the fNofPixels(270)  
+		Int_t kz = nZpix + jz -2; 
 
-		zArg1 = dZprev/sigmaDif;
-		zArg2 = dZnext/sigmaDif;
-		zProb1 = TMath::Erfc(zArg1);
-		zProb2 = TMath::Erfc(zArg2);
-		dZCharge =0.5*(zProb1-zProb2)*dCharge; 
+		Float_t zArg1 = dZprev/sigmaDif;
+		Float_t zArg2 = dZnext/sigmaDif;
+		Float_t zProb1 = TMath::Erfc(zArg1);
+		Float_t zProb2 = TMath::Erfc(zArg2);
+		Float_t dZCharge =0.5*(zProb1-zProb2)*dCharge; 
 
-		//printf("dZCharge %f \n",dZCharge);
 
 		// ----------- holes diffusion in X(r*phi) direction  --------
 
@@ -333,32 +342,32 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
 		       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; 
+		     Int_t kx = nXpix + jx -2;  
 
-		     //printf("dXCharge %f \n",dXCharge);
+		     Float_t xArg1 = dXprev/sigmaDif;
+		     Float_t xArg2 = dXnext/sigmaDif;
+		     Float_t xProb1 = TMath::Erfc(xArg1);
+		     Float_t xProb2 = TMath::Erfc(xArg2);
+		     Float_t dXCharge =0.5*(xProb1-xProb2)*dZCharge; 
 
 		     if(dXCharge > 1.) {
-		       index = lz-1;
+		       Int_t index = kz-1;
+
 		       if (first) {
                           indexRange[0]=indexRange[1]=index;
-                          indexRange[2]=indexRange[3]=lx-1;
+                          indexRange[2]=indexRange[3]=kx-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);
+                       indexRange[0]=TMath::Min(indexRange[0],kz-1);
+                       indexRange[1]=TMath::Max(indexRange[1],kz-1);
+                       indexRange[2]=TMath::Min(indexRange[2],kx-1);
+                       indexRange[3]=TMath::Max(indexRange[3],kx-1);
+
 		       // build the list of digits for this module	
-                       signal=fMapA2->GetSignal(index,lx-1);
+                       Double_t signal=fMapA2->GetSignal(index,kx-1);
                        signal+=dXCharge;
-                       fMapA2->SetHit(index,lx-1,(double)signal);
+                       fMapA2->SetHit(index,kx-1,(double)signal);
 		     }      // dXCharge > 1 e-
 		  }       // jx loop
 		}       // dZCharge > 1 e-
@@ -371,11 +380,12 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
         }
 	yPrev = yPix;  //ch
 
-	if (lasttrack != idtrack || hit==(nhits-1)) {
-            GetList(idtrack,pList,indexRange);
+	if (lasttrack != itrack || hit==(nhits-1)) {
+            GetList(itrack,idhit,pList,indexRange);
             first=kTRUE;
 	}
-	lasttrack=idtrack;
+
+	lasttrack=itrack;
     }   // hit loop inside the module
 
    
@@ -390,47 +400,55 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t
 } 
 
 //---------------------------------------------
-void AliITSsimulationSPD::GetList(Int_t label,Float_t **pList,Int_t *indexRange) {
-  // loop over nonzero digits
+void AliITSsimulationSPD::GetList(Int_t label,Int_t idhit,Float_t **pList,Int_t *indexRange)
+{
+  // lop over nonzero digits
 
-  Int_t ix,iz,globalIndex;
-  Float_t signal;
-  Float_t highest,middle,lowest;
+   
+  //set protection
+  for(int k=0;k<4;k++) {
+     if (indexRange[k] < 0) indexRange[k]=0;
+  }
 
-  for(iz=indexRange[0];izGetSignal(iz,ix);
+  for(Int_t iz=indexRange[0];izGetSignal(iz,ix);
+	if (!signal) continue;
+
+        Int_t globalIndex = iz*fNPixelsX+ix; // GlobalIndex starts from 0!
         if(!pList[globalIndex]){
         
            // 
-	   // Create new list (6 elements - 3 signals and 3 tracks + total sig)
+	   // Create new list (9 elements - 3 signals and 3 tracks + 3 hits)
 	   //
 
-           pList[globalIndex] = new Float_t [6];
+           pList[globalIndex] = new Float_t [9];
 
-	   // set list to -2 
+	   // set list to -3 
 
-	   *pList[globalIndex] = -2.;
-	   *(pList[globalIndex]+1) = -2.;
-	   *(pList[globalIndex]+2) = -2.;
+	   *pList[globalIndex] = -3.;
+	   *(pList[globalIndex]+1) = -3.;
+	   *(pList[globalIndex]+2) = -3.;
 	   *(pList[globalIndex]+3) =  0.;
 	   *(pList[globalIndex]+4) =  0.;
 	   *(pList[globalIndex]+5) =  0.;
+	   *(pList[globalIndex]+6) = -1.;
+	   *(pList[globalIndex]+7) = -1.;
+	   *(pList[globalIndex]+8) = -1.;
 
 
 	   *pList[globalIndex] = (float)label;
 	   *(pList[globalIndex]+3) = signal;
+	   *(pList[globalIndex]+6) = (float)idhit;
         }
         else{
 
 	  // check the signal magnitude
 
-          highest = *(pList[globalIndex]+3);
-          middle = *(pList[globalIndex]+4);
-          lowest = *(pList[globalIndex]+5);
+          Float_t highest = *(pList[globalIndex]+3);
+          Float_t middle = *(pList[globalIndex]+4);
+          Float_t lowest = *(pList[globalIndex]+5);
 
           signal -= (highest+middle+lowest);
 
@@ -448,6 +466,10 @@ void AliITSsimulationSPD::GetList(Int_t label,Float_t **pList,Int_t *indexRange)
             *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
             *(pList[globalIndex]+1) = *pList[globalIndex];
             *pList[globalIndex] = label;
+
+            *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
+            *(pList[globalIndex]+7) = *(pList[globalIndex]+6);
+            *(pList[globalIndex]+6) = idhit;
 	  }
           else if (signal>middle){
             *(pList[globalIndex]+5) = middle;
@@ -455,10 +477,14 @@ void AliITSsimulationSPD::GetList(Int_t label,Float_t **pList,Int_t *indexRange)
 
             *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
             *(pList[globalIndex]+1) = label;
+
+            *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
+            *(pList[globalIndex]+7) = idhit;
 	  }
           else{
             *(pList[globalIndex]+5) = signal;
             *(pList[globalIndex]+2) = label;
+            *(pList[globalIndex]+8) = idhit;
 	  }
         }
     } // end of loop pixels in x
@@ -469,8 +495,10 @@ void AliITSsimulationSPD::GetList(Int_t label,Float_t **pList,Int_t *indexRange)
 
 
 //---------------------------------------------
-void AliITSsimulationSPD::ChargeToSignal(Float_t **pList) {
-  // charge to signal  
+void AliITSsimulationSPD::ChargeToSignal(Float_t **pList)
+{
+  // add noise and electronics, perform the zero suppression and add the
+  // digit to the list
 
   AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
   
@@ -478,48 +506,54 @@ void AliITSsimulationSPD::ChargeToSignal(Float_t **pList) {
   TRandom *random = new TRandom(); 
   Float_t threshold = (float)fResponse->MinVal();
 
-  Int_t digits[3], tracks[3],gi,j1;
+  Int_t digits[3], tracks[3], hits[3],gi,j1;
   Float_t charges[3];
   Float_t electronics;
   Float_t signal,phys;
-  Int_t iz,ix;
-  for(iz=0;izGaus();
       signal = (float)fMapA2->GetSignal(iz,ix);
       signal += electronics;
+      gi =iz*fNPixelsX+ix; // global index
       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));
+	   if (pList[gi]) {
+	     tracks[j1] = (Int_t)(*(pList[gi]+j1));
+	     hits[j1] = (Int_t)(*(pList[gi]+j1+6));
+	   }else {
+	     tracks[j1]=-2; //noise
+	     hits[j1] = -1;
+	   }
 	   charges[j1] = 0;
 	 }
          phys=0;
-	 aliITS->AddDigit(0,phys,digits,tracks,charges);
-         if(pList[gi]) delete [] pList[gi];
+	 aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
       }
+      if(pList[gi]) delete [] pList[gi];
     }
   }
   delete [] pList;
 
-
 }
 
 
 //____________________________________________
 
-void AliITSsimulationSPD::CreateHistograms() {
-  // CreateHistograms
+void AliITSsimulationSPD::CreateHistograms()
+{
+  // create 1D histograms for tests
+
+      printf("SPD - create histograms\n");
 
-      Int_t i;
-      for(i=0;iAppend(candnum);
+	   Char_t pixelz[4];
+	   sprintf(pixelz,"%d",i+1);
+	   spdname->Append(pixelz);
 	   (*fHis)[i] = new TH1F(spdname->Data(),"SPD maps",
                               fNPixelsX,0.,(Float_t) fNPixelsX);
 	   delete spdname;
@@ -529,13 +563,22 @@ void AliITSsimulationSPD::CreateHistograms() {
 
 //____________________________________________
 
-void AliITSsimulationSPD::ResetHistograms() {
+void AliITSsimulationSPD::ResetHistograms()
+{
     //
     // Reset histograms for this detector
     //
-    Int_t i;
-    for(i=0;iReset();
     }
 
 }
+
+
+
+
+
+
+
+
+
diff --git a/ITS/AliITSsimulationSPD.h b/ITS/AliITSsimulationSPD.h
index 095052baef8..2e022b561c5 100644
--- a/ITS/AliITSsimulationSPD.h
+++ b/ITS/AliITSsimulationSPD.h
@@ -22,7 +22,7 @@ public:
 
   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 GetList(Int_t track, Int_t hit, Float_t **pList, Int_t *IndexRange);
 
   void CreateHistograms();
   void ResetHistograms();
diff --git a/ITS/AliITSsimulationSSD.cxx b/ITS/AliITSsimulationSSD.cxx
index 345dd7a1a03..27650cf59b8 100644
--- a/ITS/AliITSsimulationSSD.cxx
+++ b/ITS/AliITSsimulationSSD.cxx
@@ -1,23 +1,7 @@
-/**************************************************************************
- * 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 
 #include 
 
-#include "AliITSsegmentationSSD.h"
-#include "AliITSresponseSSD.h"
 #include "AliITSsimulationSSD.h"
 #include "AliITSdictSSD.h"
 #include "AliITSdcsSSD.h"
@@ -38,17 +22,16 @@ AliITSsimulationSSD::AliITSsimulationSSD(AliITSsegmentation *seg,
     fNstrips = fSegmentation->Npx();
     fPitch = fSegmentation->Dpx(0);
     
-    fP = new TArrayF(fNstrips); 
-    fN = new TArrayF(fNstrips);
+    fP = new TArrayF(fNstrips+1); 
+    fN = new TArrayF(fNstrips+1);
      
-    fTracksP = new AliITSdictSSD[fNstrips];
-    fTracksN = new AliITSdictSSD[fNstrips];
+    fTracksP = new AliITSdictSSD[fNstrips+1];
+    fTracksN = new AliITSdictSSD[fNstrips+1];
+
     
     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 
@@ -74,7 +57,7 @@ AliITSsimulationSSD::AliITSsimulationSSD(AliITSsimulationSSD &source){
 //____________________________________________________________________________
 AliITSsimulationSSD::~AliITSsimulationSSD() {
   // anihilator    
-    
+
     if(fP) delete fP;
     if(fN) delete fN;
     
@@ -94,7 +77,6 @@ void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t module,
     
     TObjArray *hits = mod->GetHits();
     Int_t nhits = hits->GetEntriesFast();
-    //printf("SSD: nhits %d\n",nhits);
     if (!nhits) return;
 
     Int_t i;
@@ -111,6 +93,7 @@ void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t module,
     }
  
    
+
     ApplyNoise();
     ApplyCoupling();    
     ApplyThreshold();
@@ -129,9 +112,9 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
     Float_t    dsP, dsN;
     Float_t    sP, sN;
     Float_t    eP, eN;
-    Float_t    arrayEP[10];
+    Float_t    arrayEP[10];         // hard-wired number of steps
     Float_t    arrayEN[10];
-    Int_t      track = 0;
+    Int_t      track = -1;
        
     Float_t    ionization = 0;
     Float_t    signal;
@@ -157,7 +140,7 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
     
         
     if (hitI->GetTrack() == hitE->GetTrack()) 
-      //track = idtrack;
+       //track = idtrack;
        track = hitI->GetTrack();
     else 
        printf("!!! Emergency !!!\n");
@@ -170,8 +153,6 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
     Float_t xI, yI, zI;
     hitI->GetPositionL(xI, yI, zI);
     
-    //Float_t zI =  hitI->GetZL();
-
     xI *= kconvm;
     yI *= kconvm;
     zI *= kconvm;
@@ -179,8 +160,6 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
     Float_t xE, yE, zE;
     hitE->GetPositionL(xE, yE, zE);
     
-    //Float_t zE =  hitE->GetZL();
-  
     xE *= kconvm;
     yE *= kconvm;
     zE *= kconvm;
@@ -191,7 +170,7 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
     
     // Debuging
     /*
-    fSegmentation->GetCellIxz(xI,zI,stripP,stripN);
+    fSegmentation->GetPadIxz(xI,zI,stripP,stripN);
    
        printf("%5d %8.3f %8.3f %8.3f %8.3f %d %d  %d\n", 
              hitNo, xI, zI, dx, dz, 
@@ -204,9 +183,8 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
     
     eP=0;
     eN=0;
-    //fNparticles++;
     
-    for(i=0; iLandau(ionization/fSteps, ionization/(4*fSteps));
       //        arrayEN[i] = gRandom->Landau(ionization/fSteps, ionization/(4*fSteps));
@@ -242,8 +220,8 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
         
         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);
+        fSegmentation->GetPadIxz(xI,zI,stripP,stripN);
+        //printf("hitNo %d i xI zI stripP stripN %d %f %f %d %d\n",hitNo,i,xI, zI, stripP, stripN);
         dsP    = Get2Strip(1,stripP,xI, zI); // Between 0-1
         dsN    = Get2Strip(0,stripN,xI, zI); // Between 0-1
 
@@ -257,13 +235,8 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
         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++) {
-            
+        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) {
@@ -272,10 +245,9 @@ void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
                (*dict).AddTrack(track);
             } 
 	}  // end for j loop over neighboring strips
-        for(j=-1; j<2; j++) {
-            
+
+        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) {
@@ -315,7 +287,6 @@ void AliITSsimulationSSD::ApplyNoise() {
 
 void AliITSsimulationSSD::ApplyCoupling() {
   // Apply the effecto of electronic coupling between channels    
-
     Int_t i;
     for(i = 1; iGetCouplingPL() + (*fP)[i+1]*fDCS->GetCouplingPR();
@@ -336,7 +307,6 @@ void AliITSsimulationSSD::ApplyThreshold() {
     for(i=0; i noiseP*4) ? (*fP)[i] : 0;
        (*fN)[i] = ((*fN)[i] > noiseN*4) ? (*fN)[i] : 0; 
-       //printf("SSD:(*fP)[i] (*fN)[i] %f %f \n",(*fP)[i], (*fN)[i]);
     }
         
 }
@@ -350,52 +320,53 @@ void AliITSsimulationSSD::ApplyDAQ() {
     Float_t noiseP, noiseN;
     fResponse->GetNoiseParam(noiseP,noiseN);
 
-    // Set signal = 0 if invalid strip
+    char opt[30],dummy[20];
+    fResponse->ParamOptions(opt,dummy);
+
     Int_t i,j;
-    for(i=0; iIsValidP(i))) (*fP)[i] = 0;
-       if (!(fDCS->IsValidN(i))) (*fN)[i] = 0;
+    if (strstr(opt,"SetInvalid")) {
+      // Set signal = 0 if invalid strip
+      for(i=0; iIsValidP(i))) (*fP)[i] = 0;
+	 if (!(fDCS->IsValidN(i))) (*fN)[i] = 0;
+      }
     }
     
-    Int_t digits[3], tracks[3];
+    Int_t digits[3], tracks[3], hits[3];
     Float_t charges[3];
     Float_t phys=0;
+    for(i=0;i<3;i++) tracks[i]=0;
     for(i=0; iGetNTracks(); j++) {
-             if(j>2) continue;
-             tracks[j] = (fTracksP+i)->GetTrack(j);
-             charges[j] = 0;
+            if(j>2) continue;
+	    if((fTracksP+i)->GetNTracks()) tracks[j]=(fTracksP+i)->GetTrack(j);
+	    else tracks[j]=-2;
+	    charges[j] = 0;
+	    hits[j] = -1;
           }
-          its->AddDigit(2,phys,digits,tracks,charges);
+          its->AddSimDigit(2,phys,digits,tracks,hits,charges);
           
-          //cout << (fTracksP+i)->GetNTracks(); 
-          //
-	  //if ((fTracksP+i)->GetNTracks() == 0) {
-          //   cout << d.fCoord2 << " " << d.fSignal << "\n"; 
-          //}
     }
     
     
     for(i=0; iGetNTracks(); j++) {
-             if(j>2) continue;
-             tracks[j] = (fTracksN+i)->GetTrack(j); 
-             charges[j] = 0;
+          for( j=0; j<(fTracksN+i)->GetNTracks(); j++) {
+            if(j>2) continue;
+            if((fTracksN+i)->GetNTracks()) tracks[j]=(fTracksN+i)->GetTrack(j);
+	    else tracks[j]=-2;
+            charges[j] = 0;
+	    hits[j] = -1;
           }
-          its->AddDigit(2,phys,digits,tracks,charges);
+          its->AddSimDigit(2,phys,digits,tracks,hits,charges);
           
-          //cout << (fTracksN+i)->GetNTracks();
-          //if ((fTracksN+i)->GetNTracks() == 0) {
-          //   cout << d.fCoord2 << " " << d.fSignal << "\n"; 
-          //}
     }
     
 }
@@ -405,6 +376,7 @@ void AliITSsimulationSSD::ApplyDAQ() {
 
 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) ;
 } 
diff --git a/ITS/AliITSsimulationSSD.h b/ITS/AliITSsimulationSSD.h
index f3a6181a761..bb89fc69d03 100644
--- a/ITS/AliITSsimulationSSD.h
+++ b/ITS/AliITSsimulationSSD.h
@@ -3,9 +3,7 @@
 
 #include 
 
-#include "AliITSdcsSSD.h"
 #include "AliITSsimulation.h"
-#include "AliITSdictSSD.h"
 
 
 class AliITSdictSSD;
@@ -24,22 +22,12 @@ public:
   void DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy);  
   void HitToDigit(Int_t &hit,Int_t idtrack,Int_t nhits,TObjArray *hits);            
 
-  TArrayF* GetSignalP() {
-                         // return the signal of P strip
-                         return fP;
-								}
-  TArrayF* GetSignalN() {
-                         // return the signal of N strip
-                         return fN;
-								}
+  // return the pointer to the signal array of P strip
+  TArrayF* GetSignalP() {return fP;}
+  // return the pointer to the signal array of N strip
+  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();
@@ -68,7 +56,7 @@ protected:
   ClassDef(AliITSsimulationSSD,1)
     
     
-    };
+};
 
 
 #endif
diff --git a/ITS/AliITSstatistics.cxx b/ITS/AliITSstatistics.cxx
index e029abb7fb7..6ec5d769226 100644
--- a/ITS/AliITSstatistics.cxx
+++ b/ITS/AliITSstatistics.cxx
@@ -34,8 +34,7 @@ AliITSstatistics::AliITSstatistics(Int_t order) : TObject(){
     fOrder = order;
     fx = new Double_t[order];
     fw = new Double_t[order];
-    Int_t i;
-    for(i=0;ifOrder = source.fOrder;
-       this->fN = source.fN;
-       this->fx = new Double_t[this->fOrder];
-       this->fw = new Double_t[this->fOrder];
-       for(i=0;ifx[i] = source.fx[i];
-	 this->fw[i] = source.fw[i];
-       } // end for i
-     }else{
-       this->fx = 0;
-       this->fw = 0;
-       this->fN = 0;
-       this->fOrder = 0;
-     }// end if source.fOrder!=0
-     return *this;
+	  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(Int_t i=0;ifx[i] = source.fx[i];
+					this->fw[i] = source.fw[i];
+			 } // end for i
+	  }else{
+	       this->fx = 0;
+			 this->fw = 0;
+			 this->fN = 0;
+			 this->fOrder = 0;
+	  }// end if source.fOrder!=0
+	  return *this;
 }
 //_______________________________________________________________
 AliITSstatistics::AliITSstatistics(AliITSstatistics &source){
 // Copy constructor
 
-  Int_t i;
-  if(this==&source) return;
-  if(source.fOrder!=0){
-    this->fOrder = source.fOrder;
-    this->fN = source.fN;
-    this->fx = new Double_t[this->fOrder];
-    this->fw = new Double_t[this->fOrder];
-    for(i=0;ifx[i] = source.fx[i];
-      this->fw[i] = source.fw[i];
-    } // end for i
-  }else{
-    this->fx = 0;
-    this->fw = 0;
-    this->fN = 0;
-    this->fOrder = 0;
-  }// end if source.fOrder!=0
+     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(Int_t i=0;ifx[i] = source.fx[i];
+					this->fw[i] = source.fw[i];
+			 } // end for i
+	  }else{
+	       this->fx = 0;
+			 this->fw = 0;
+			 this->fN = 0;
+			 this->fOrder = 0;
+	  }// end if source.fOrder!=0
 }
 //_______________________________________________________________
 void AliITSstatistics::Reset(){
 //
 // reset all values to zero
 //
-    Int_t i;
-    for(i=0;ikBig || x>kBig || w>kBig) return;
 
-    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;ifOrder = source.fOrder;
-    this->fN = source.fN;
-    this->fx = new Double_t[this->fOrder];
-    this->fw = new Double_t[this->fOrder];
-    for(i=0;ifx[i] = source.fx[i];
-      this->fw[i] = source.fw[i];
-    } // end for i
-  }else{
-    this->fx = 0;
-    this->fw = 0;
-    this->fN = 0;
-    this->fOrder = 0;
-  }// end if source.fOrder!=0
-  return *this;
+     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(Int_t i=0;ifx[i] = source.fx[i];
+					this->fw[i] = source.fw[i];
+			 } // end for i
+	  }else{
+	       this->fx = 0;
+			 this->fw = 0;
+			 this->fN = 0;
+			 this->fOrder = 0;
+	  }// end if source.fOrder!=0
+	  return *this;
 }
 //_______________________________________________________________
 AliITSstatistics2::AliITSstatistics2(AliITSstatistics2 &source){
 // Copy constructor
 
-  Int_t i;
-  if(this==&source) return;
-  if(source.fOrder!=0){
-    this->fOrder = source.fOrder;
-    this->fN = source.fN;
-    this->fx = new Double_t[this->fOrder];
-    this->fw = new Double_t[this->fOrder];
-    for(i=0;ifx[i] = source.fx[i];
-      this->fw[i] = source.fw[i];
-    } // end for i
-  }else{
-    this->fx = 0;
-    this->fw = 0;
-    this->fN = 0;
-    this->fOrder = 0;
-  }// end if source.fOrder!=0
+     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(Int_t i=0;ifx[i] = source.fx[i];
+					this->fw[i] = source.fw[i];
+			 } // end for i
+	  }else{
+	       this->fx = 0;
+			 this->fw = 0;
+			 this->fN = 0;
+			 this->fOrder = 0;
+	  }// end if source.fOrder!=0
 }
 
 void AliITSstatistics2::Reset(){
 //
 // Reset/zero statistics
 //
-    Int_t i;
-    for(i=0;ikBig || x>kBig || w>kBig) return;
+
+
     fN++;
     for(i=0;i
+
+
+
+//_____________________________________________________________________________
+class AliITStrack : public TObject {
+
+public:
+
+  AliITStrack() {}
+  AliITStrack(const AliITStrack& t) {}
+  virtual ~AliITStrack() {}
+
+
+  Bool_t IsSortable() const {return kTRUE;}
+
+  ClassDef(AliITStrack,1)  // ITS reconstructed tracks
+};
+
+#endif
diff --git a/ITS/AliITSv1.cxx b/ITS/AliITSv1.cxx
index 2095572ee75..27c52f873fc 100644
--- a/ITS/AliITSv1.cxx
+++ b/ITS/AliITSv1.cxx
@@ -15,17 +15,6 @@
 
 /*
 $Log$
-Revision 1.14.2.6  2000/06/12 19:14:32  barbera
-Remove partical transision to new Config.C calling convension. Bug Found.
-
-Revision 1.14.2.5  2000/06/12 18:15:13  barbera
-fixed posible compilation errors on HP unix. Modifided default constructor
-for use with new calling requirements. Removed creation of hits from this
-cource geometry.
-
-Revision 1.14.2.4  2000/06/11 20:37:26  barbera
-coding convenstion update.
-
 Revision 1.14.2.2  2000/05/19 10:09:21  nilsen
 fix for bug with HP and Sun unix + fix for event display in ITS-working branch
 
@@ -96,34 +85,39 @@ Introduction of the Copyright and cvs Log
 ClassImp(AliITSv1)
  
 //_____________________________________________________________________________
-  AliITSv1::AliITSv1()/*:AliITS("ITS","TDR cource version")*/ {
+AliITSv1::AliITSv1() {
 ////////////////////////////////////////////////////////////////////////
 //    Standard default constructor for the ITS version 1.
 ////////////////////////////////////////////////////////////////////////
-    fId1N = 6;
-    fId1Name = new char*[fId1N];
-    fId1Name[0] = "ITS1";
-    fId1Name[1] = "ITS2";
-    fId1Name[2] = "ITS3";
-    fId1Name[3] = "ITS4";
-    fId1Name[4] = "ITS5";
-    fId1Name[5] = "ITS6";
-    printf("Created ITS TDR Cource version\n");
+
+  fIdN = 6;
+  fIdName = new TString[fIdN];
+  fIdName[0] = "ITS1";
+  fIdName[1] = "ITS2";
+  fIdName[2] = "ITS3";
+  fIdName[3] = "ITS4";
+  fIdName[4] = "ITS5";
+  fIdName[5] = "ITS6";
+  fIdSens    = new Int_t[fIdN];
+  for (Int_t i=0;ifId1N = source.fId1N;
-    this->fId1Name = new char*[fId1N];
-    Int_t i;
-    for(i=0;i<6;i++) strcpy(this->fId1Name[i],source.fId1Name[i]);
+    printf("Not allowed to copy AliITSv1\n");
     return;
 }
 //_____________________________________________________________________________
@@ -143,10 +134,7 @@ AliITSv1& AliITSv1::operator=(const AliITSv1 &source){
 //    Assignment operator for the ITS version 1.
 ////////////////////////////////////////////////////////////////////////
   if(&source == this) return *this;
-  this->fId1N = source.fId1N;
-  this->fId1Name = new char*[fId1N];
-  Int_t i;
-  for(i=0;i<6;i++) strcpy(this->fId1Name[i],source.fId1Name[i]);
+    printf("Not allowed to copy AliITSv1\n");
   return *this;
 }
 //_____________________________________________________________________________
@@ -154,14 +142,15 @@ AliITSv1::~AliITSv1() {
 ////////////////////////////////////////////////////////////////////////
 //    Standard destructor for the ITS version 1.
 ////////////////////////////////////////////////////////////////////////
-  delete [] fId1Name;
-}//__________________________________________________________________________
+}
+
+//__________________________________________________________________________
 void AliITSv1::BuildGeometry(){
 ////////////////////////////////////////////////////////////////////////
 //    Geometry builder for the ITS version 1.
 ////////////////////////////////////////////////////////////////////////
     TNode *node, *top;
-    const Int_t kColorITS=kYellow;
+    const int kColorITS=kYellow;
     //
     top = gAlice->GetGeometry()->GetNode("alice");
 
@@ -232,7 +221,7 @@ void AliITSv1::CreateGeometry(){
   Int_t *idtmed = fIdtmed->GetArray()-199;
   
   //     CONVERT INTO CM (RL(SI)=9.36 CM) 
-  for(i = 0; i < 6; ++i) {
+  for (i = 0; i < 6; ++i) {
     drl[i] = drl[i] / 100. * 9.36;
   }
   
@@ -266,7 +255,7 @@ void AliITSv1::CreateGeometry(){
   
   //     PARAMETERS FOR SMALL (1/2) ITS 
 
-  for(i = 0; i < 6; ++i) {
+  for (i = 0; i < 6; ++i) {
     dzl[i] /= 2.;
     dzb[i] /= 2.;
   }
@@ -283,7 +272,7 @@ void AliITSv1::CreateGeometry(){
   
   //     EQUAL DISTRIBUTION INTO THE 6 LAYERS 
   rstep = drcatpc / 6.;
-  for(i = 0; i < 6; ++i) {
+  for (i = 0; i < 6; ++i) {
     drcac[i] = (i+1) * rstep;
   }
 
@@ -294,7 +283,7 @@ void AliITSv1::CreateGeometry(){
   //     PACK IN PHI AS MUCH AS POSSIBLE 
   //     NOW PACK USING THICKNESS 
   
-  for(i = 0; i < 6; ++i) {
+  for (i = 0; i < 6; ++i) {
     
 //     PACKING FACTOR 
     fp = rl[5] / rl[i];
@@ -363,7 +352,7 @@ void AliITSv1::CreateGeometry(){
   //     PCB (layer #3 and #4) 
   
   gMC->Gsvolu("IPCB", "TUBE", idtmed[233], dits, 0);
-  for(i = 2; i < 4; ++i) {
+  for (i = 2; i < 4; ++i) {
     dits[0] = rl[i];
     dits[1] = dits[0] + drpcb[i];
     dits[2] = dzb[i] / 2.;
@@ -375,7 +364,7 @@ void AliITSv1::CreateGeometry(){
   //     COPPER (layer #3 and #4) 
   
   gMC->Gsvolu("ICO2", "TUBE", idtmed[234], dits, 0);
-  for(i = 2; i < 4; ++i) {
+  for (i = 2; i < 4; ++i) {
     dits[0] = rl[i] + drpcb[i];
     dits[1] = dits[0] + drcu[i];
     dits[2] = dzb[i] / 2.;
@@ -387,7 +376,7 @@ void AliITSv1::CreateGeometry(){
   //     CERAMICS (layer #3 and #4) 
   
   gMC->Gsvolu("ICER", "TUBE", idtmed[235], dits, 0);
-  for(i = 2; i < 4; ++i) {
+  for (i = 2; i < 4; ++i) {
     dits[0] = rl[i] + drpcb[i] + drcu[i];
     dits[1] = dits[0] + drcer[i];
     dits[2] = dzb[i] / 2.;
@@ -399,7 +388,7 @@ void AliITSv1::CreateGeometry(){
   //     SILICON (layer #3 and #4) 
   
   gMC->Gsvolu("ISI2", "TUBE", idtmed[226], dits, 0);
-  for(i = 2; i < 4; ++i) {
+  for (i = 2; i < 4; ++i) {
     dits[0] = rl[i] + drpcb[i] + drcu[i] + drcer[i];
     dits[1] = dits[0] + drsi[i];
     dits[2] = dzb[i] / 2.;
@@ -411,7 +400,7 @@ void AliITSv1::CreateGeometry(){
   //     PLASTIC (G10FR4) (layer #5 and #6) 
   
   gMC->Gsvolu("IPLA", "TUBE", idtmed[262], dits, 0);
-  for(i = 4; i < 6; ++i) {
+  for (i = 4; i < 6; ++i) {
     dits[0] = rl[i];
     dits[1] = dits[0] + drpla[i];
     dits[2] = dzb[i] / 2.;
@@ -423,7 +412,7 @@ void AliITSv1::CreateGeometry(){
   //     COPPER (layer #5 and #6) 
   
   gMC->Gsvolu("ICO3", "TUBE", idtmed[259], dits, 0);
-  for(i = 4; i < 6; ++i) {
+  for (i = 4; i < 6; ++i) {
     dits[0] = rl[i] + drpla[i];
     dits[1] = dits[0] + drcu[i];
     dits[2] = dzb[i] / 2.;
@@ -435,7 +424,7 @@ void AliITSv1::CreateGeometry(){
   //     EPOXY (layer #5 and #6) 
   
   gMC->Gsvolu("IEPX", "TUBE", idtmed[262], dits, 0);
-  for(i = 4; i < 6; ++i) {
+  for (i = 4; i < 6; ++i) {
     dits[0] = rl[i] + drpla[i] + drcu[i];
     dits[1] = dits[0] + drepx[i];
     dits[2] = dzb[i] / 2.;
@@ -447,7 +436,7 @@ void AliITSv1::CreateGeometry(){
   //     SILICON (layer #5 and #6) 
   
   gMC->Gsvolu("ISI3", "TUBE", idtmed[251], dits, 0);
-  for(i = 4; i < 6; ++i) {
+  for (i = 4; i < 6; ++i) {
     dits[0] = rl[i] + drpla[i] + drcu[i] + drepx[i];
     dits[1] = dits[0] + drsi[i];
     dits[2] = dzb[i] / 2.;
@@ -459,7 +448,7 @@ void AliITSv1::CreateGeometry(){
   //    SUPPORT 
   
   gMC->Gsvolu("ISUP", "TUBE", idtmed[274], dits, 0);
-  for(i = 0; i < 6; ++i) {
+  for (i = 0; i < 6; ++i) {
     dits[0] = rl[i];
     if (i < 5) dits[1] = rl[i+1];
     else       dits[1] = rlim;
@@ -472,7 +461,7 @@ void AliITSv1::CreateGeometry(){
   // CABLES (HORIZONTAL) 
   
   gMC->Gsvolu("ICHO", "TUBE", idtmed[278], dits, 0);
-  for(i = 0; i < 6; ++i) {
+  for (i = 0; i < 6; ++i) {
     dits[0] = rl[i];
     dits[1] = dits[0] + drca;
     dits[2] = (rzcone + TMath::Tan(acone) * (rl[i] - rl[0]) - (dzl[i]+ dzb[i] + drsu)) / 2.;
@@ -505,7 +494,7 @@ void AliITSv1::CreateGeometry(){
   
   pcits[2] = 2.;
   gMC->Gsvolu("ICCO", "PCON", idtmed[278], pcits, 0);
-  for(i = 1; i < 6; ++i) {
+  for (i = 1; i < 6; ++i) {
     pcits[0] = -dphi[i] / 2.;
     pcits[1] = dphi[i];
     if (i < 5) {
@@ -560,7 +549,7 @@ void AliITSv1::CreateGeometry(){
   r0 = rend;
   z0 = zend;
   dz = (xltpc - zend) / 9.;
-  for(i = 0; i < 9; ++i) {
+  for (i = 0; i < 9; ++i) {
     zi = z0 + i*dz + dz / 2.;
     ri = r0 + (zi - z0) * TMath::Tan(acable * kDegrad);
     dphii = dphi[5] * r0 / ri;
@@ -770,17 +759,7 @@ void AliITSv1::Init(){
 ////////////////////////////////////////////////////////////////////////
 //     Initialise the ITS after it has been created.
 ////////////////////////////////////////////////////////////////////////
-    Int_t i,j,l;
-
-    fIdN       = fId1N;;
-    fIdName    = new char*[fIdN];
-    fIdSens    = new Int_t[fIdN];
-    for(i=0;iEdep();
     hits[7]=gMC->TrackTime();
     new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->CurrentTrack(),vol,hits);
-    we no longer generate hit from the cource version.
-  */
-  return;
 }
 //____________________________________________________________________________
 void AliITSv1::Streamer(TBuffer &R__b){
@@ -920,21 +894,11 @@ void AliITSv1::Streamer(TBuffer &R__b){
 // dosen't contain any "real" data to be saved, it doesn't.
 ////////////////////////////////////////////////////////////////////////
 
-    printf("AliITSv1Streamer Starting\n");
    if (R__b.IsReading()) {
       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
       AliITS::Streamer(R__b);
-      // This information does not need to be read. It is "hard wired"
-      // into this class via its creators.
-      //R__b >> fId1N;
-      //R__b.ReadArray(fId1Name);
    } else {
       R__b.WriteVersion(AliITSv1::IsA());
       AliITS::Streamer(R__b);
-      // This information does not need to be saved. It is "hard wired"
-      // into this class via its creators.
-      //R__b << fId1N;
-      //R__b.WriteArray(fId1Name, __COUNTER__);
    } // end if R__b.IsReading()
-    printf("AliITSv1Streamer Finishing\n");
 }
diff --git a/ITS/AliITSv1.h b/ITS/AliITSv1.h
index 538e8bca74e..5fc24b7a323 100644
--- a/ITS/AliITSv1.h
+++ b/ITS/AliITSv1.h
@@ -24,20 +24,12 @@ class AliITSv1 : public AliITS {
     virtual void   CreateMaterials();
     virtual void   Init(); 
     virtual Int_t  IsVersion() const {
-	                                   // returns the ITS version number 
-	                                   return 1;
-												 } 
+      // returns the ITS version number 
+      return 1;
+    } 
     virtual void   DrawModule();
     virtual void   StepManager();
 
- private:
-    Int_t fId1N; // The number of layers for geometry version 5
-                 // The name of the layers as defined in the Geant tree.
-
-	 char **fId1Name; // They are the names of the sensitive volumes
- 
-
-  
     ClassDef(AliITSv1,1)  //Hits manager for set:ITS version 1 cource Geometry
 };
  
diff --git a/ITS/AliITSv3.cxx b/ITS/AliITSv3.cxx
index c0f9171da77..345dcdac272 100644
--- a/ITS/AliITSv3.cxx
+++ b/ITS/AliITSv3.cxx
@@ -15,16 +15,6 @@
 
 /*
 $Log$
-Revision 1.11.4.8  2000/06/12 19:14:40  barbera
-Remove partical transision to new Config.C calling convension. Bug Found.
-
-Revision 1.11.4.7  2000/06/12 18:15:38  barbera
-fixed posible compilation errors on HP unix. Modifided default constructor
-for use with new calling requirements.
-
-Revision 1.11.4.6  2000/06/11 20:37:41  barbera
-coding convenstion update.
-
 Revision 1.11.4.4  2000/05/19 10:09:51  nilsen
 fix for bug with HP and Sun unix + fix for event display in ITS-working branch
 
@@ -99,20 +89,22 @@ Introduction of the Copyright and cvs Log
 ClassImp(AliITSv3)
  
 //_____________________________________________________________________________
-  AliITSv3::AliITSv3()/* : AliITS("ITS","TP version")*/{
+AliITSv3::AliITSv3() {
 ////////////////////////////////////////////////////////////////////////
 //    Standard default constructor for the ITS version 3.
 ////////////////////////////////////////////////////////////////////////
-    fId3N = 6;
-    fId3Name = new char*[fId3N];
-    fId3Name[0] = "ITS1";
-    fId3Name[1] = "ITS2";
-    fId3Name[2] = "ITS3";
-    fId3Name[3] = "ITS4";
-    fId3Name[4] = "ITS5";
-    fId3Name[5] = "ITS6";
+
+    fIdN = 6;
+    fIdName = new TString[fIdN];
+    fIdName[0] = "ITS1";
+    fIdName[1] = "ITS2";
+    fIdName[2] = "ITS3";
+    fIdName[3] = "ITS4";
+    fIdName[4] = "ITS5";
+    fIdName[5] = "ITS6";
+    fIdSens    = new Int_t[fIdN];
+    for (Int_t i=0;ifId3N = source.fId3N;
-    this->fId3Name = new char*[fId3N];
-    Int_t i;
-    for(i=0;i<6;i++) strcpy(this->fId3Name[i],source.fId3Name[i]);
+    printf("Not allowed to copy AliITSv3\n");
     return;
 }
 //_____________________________________________________________________________
@@ -131,42 +120,39 @@ AliITSv3& AliITSv3::operator=(const AliITSv3 &source){
 ////////////////////////////////////////////////////////////////////////
 //    Assignment operator for the ITS version 3.
 ////////////////////////////////////////////////////////////////////////
-  if(&source == this) return *this;
-  this->fId3N = source.fId3N;
-  this->fId3Name = new char*[fId3N];
-  Int_t i;
-  for(i=0;i<6;i++) strcpy(this->fId3Name[i],source.fId3Name[i]);
-  return *this;
+    if(&source == this) return *this;
+    printf("Not allowed to copy AliITSv3\n");
+    return *this;
 }
 //_____________________________________________________________________________
 AliITSv3::~AliITSv3() {
 ////////////////////////////////////////////////////////////////////////
 //    Standard destructor for the ITS version 3.
 ////////////////////////////////////////////////////////////////////////
-  delete [] fId3Name;
 }
 //_____________________________________________________________________________
 AliITSv3::AliITSv3(const char *name, const char *title) : AliITS(name, title){
 ////////////////////////////////////////////////////////////////////////
 //    Standard constructor for the ITS version 3.
 ////////////////////////////////////////////////////////////////////////
-    fId3N = 6;
-    fId3Name = new char*[fId3N];
-    fId3Name[0] = "ITS1";
-    fId3Name[1] = "ITS2";
-    fId3Name[2] = "ITS3";
-    fId3Name[3] = "ITS4";
-    fId3Name[4] = "ITS5";
-    fId3Name[5] = "ITS6";
+    fIdN = 6;
+    fIdName = new TString[fIdN];
+    fIdName[0] = "ITS1";
+    fIdName[1] = "ITS2";
+    fIdName[2] = "ITS3";
+    fIdName[3] = "ITS4";
+    fIdName[4] = "ITS5";
+    fIdName[5] = "ITS6";
+    fIdSens    = new Int_t[fIdN];
+    for (Int_t i=0;iGetGeometry()->GetNode("alice");
 
@@ -492,7 +478,7 @@ void AliITSv3::CreateGeometry(){
   jbox2 = 0;
   
   // counter over the number of elements of layer #2 ( 
-  for(i = 1; i <= 10; ++i) {
+  for (i = 1; i <= 10; ++i) {
     
     // --- Place part # 1-2 (see sketch) 
     
@@ -1498,7 +1484,7 @@ void AliITSv3::CreateGeometry(){
   //     (IDV1) 
   
   ypos = 0.;
-  for(j = 1; j <= 5; ++j) {
+  for (j = 1; j <= 5; ++j) {
     // odd elements are up and even elements are down 
     if (j == 1) {
       xpos = dbox1[0] - dpcb[0] * 2. - dcop[0] * 2. - dcer[0] * 2. - dsil[0] * 2. - dits[0];
@@ -1734,7 +1720,7 @@ void AliITSv3::CreateGeometry(){
   //     (IDV2) 
   
   ypos = 0.;
-  for(j = 1; j <= 5; ++j) {
+  for (j = 1; j <= 5; ++j) {
     // odd element are up and even elements are down 
     if (j == 1) {
       xpos = dbox2[0] - dpcb[0] * 2. - dcop[0] * 2. - dcer[0] * 2. - dsil[0] * 2. - dits[0];
@@ -1892,7 +1878,7 @@ void AliITSv3::CreateGeometry(){
   //     mother volume (IT34) 
   //     Odd elements have large ribs and even elements have small ribs 
   
-  for(i = 1; i <= 12; ++i) {
+  for (i = 1; i <= 12; ++i) {
     atheta = (i-1) * 30.;
     AliMatrix(idrotm[i+1299], 90., atheta, 90., atheta + 90., 0.,0.);
     if (i % 2 == 0) {
@@ -2037,7 +2023,7 @@ void AliITSv3::CreateGeometry(){
   //     (IDV3) 
   
   ypos = 0.;
-  for(j = 1; j <= 7; ++j) {
+  for (j = 1; j <= 7; ++j) {
     // odd elements are down and even elements are up 
     if (j == 1) {
       xpos = dbox1[0] - dpcb[0] * 2. - dcop[0] * 2. - dcer[0] * 2. - dsil[0] * 2. - dits[0];
@@ -2283,7 +2269,7 @@ void AliITSv3::CreateGeometry(){
   //     (IDV4) 
   
   ypos = 0.;
-  for(j = 1; j <= 7; ++j) {
+  for (j = 1; j <= 7; ++j) {
     // odd elements are down and even elements are up 
     if (j == 1) {
       xpos = dbox2[0] - dpcb[0] * 2. - dcop[0] * 2. - dcer[0] * 2. - dsil[0] * 2. - dits[0];
@@ -2452,7 +2438,7 @@ void AliITSv3::CreateGeometry(){
   //     mother volume (IT34) 
   //     Odd elements have large ribs and even elements have small ribs 
   
-  for(i = 1; i <= 24; ++i) {
+  for (i = 1; i <= 24; ++i) {
     atheta = (i-1) * 15.;
     AliMatrix(idrotm[i+1399], 90., atheta, 90., atheta + 90., 0.,0.);
     if (i % 2 == 0) {
@@ -2661,7 +2647,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the sensitive part of the strips into its mother (ISV1) 
     
     ypos = 0.;
-    for(j = 1; j <= 23; ++j) {
+    for (j = 1; j <= 23; ++j) {
       if (j % 2 == 0) xpos = dbox1[0] - dits[0];
       else            xpos = -dbox1[0] + dits[0];
       zpos = ((j - 1) - 11.) * 3.91;
@@ -2671,7 +2657,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the electronics of the strips into its mother (SSV1) 
     
     ypos = 0.;
-    for(j = 1; j <= 23; ++j) {
+    for (j = 1; j <= 23; ++j) {
       if (j % 2 == 0) xpos = -dsrv[0] + .28;
       else            xpos = -dsrv[0] + .28 - dits[0] * 2. - .03;
       zpos = ((j - 1) - 11.) * 3.91 + .85;
@@ -2699,7 +2685,7 @@ void AliITSv3::CreateGeometry(){
     
     xpos = -dsrv[0] + .47 + TMath::Sqrt(3.) / 6. * 4.2;
     ypos = 0.;
-    for(j = 1; j <= 23; ++j) { // Loop was to 24. Changed to 23 to fit inside
+    for (j = 1; j <= 23; ++j) { // Loop was to 24. Changed to 23 to fit inside
                                 // volume SSV1. This is the same number of
                                 // elements as SCH5 above. Done Bjorn S. Nilsen
                                 // April 4 2000. Error found by Ivana 
@@ -2740,7 +2726,7 @@ void AliITSv3::CreateGeometry(){
     rzero   = dbox1[0] + 40.;
     runo    = dbox1[0] * 2. + 40. + dsrv[0];
     rtwo    = dbox1[0] * 2. + 40. + dela[0];
-    for(i = 1; i <= 35; ++i) {
+    for (i = 1; i <= 35; ++i) {
       atheta = (i-1) * ktwopi * kraddeg / 35. + offset2;
       AliMatrix(idrotm[i+1499], 90., atheta, 90., atheta + 90., 0., 0.);
       
@@ -2922,7 +2908,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the sensitive part of the strips into its mother (ISV2) 
     
     ypos = 0.;
-    for(j = 1; j <= 26; ++j) {
+    for (j = 1; j <= 26; ++j) {
       if (j % 2 == 0) xpos = dbox2[0] - dits[0];
       else            xpos = -dbox2[0] + dits[0];
       zpos = ((j - 1) - 12.) * 3.91 - 1.96;
@@ -2932,7 +2918,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the electronics of the strips into its mother (SSV2) 
     
     ypos = 0.;
-    for(j = 1; j <= 26; ++j) {
+    for (j = 1; j <= 26; ++j) {
       if (j % 2 == 0) xpos = -dsrv[0] + .28;
       else            xpos = -dsrv[0] + .28 - dits[0] * 2. - .03;
       zpos = ((j - 1) - 12.) * 3.91 - 1.96 + .85;
@@ -2960,7 +2946,7 @@ void AliITSv3::CreateGeometry(){
     
     xpos = -dsrv[0] + .47 + TMath::Sqrt(3.) / 6. * 4.2;
     ypos = 0.;
-    for(j = 1; j <= 27; ++j) {
+    for (j = 1; j <= 27; ++j) {
       zpos = ((j - 1) - 12.) * 3.91 - 1.96 - 4.2/2.;
       gMC->Gspos("SFR6", j, "SSV2", xpos, ypos, zpos, 0, "ONLY");
     }
@@ -2997,7 +2983,7 @@ void AliITSv3::CreateGeometry(){
     rzero   = dbox2[0] + 45.;
     runo    = dbox2[0] * 2. + 45. + dsrv[0];
     rtwo    = dbox2[0] * 2. + 45. + dela[0];
-    for(i = 1; i <= 39; ++i) {
+    for (i = 1; i <= 39; ++i) {
       atheta = (i-1) * ktwopi * kraddeg / 39. + offset2;
       AliMatrix(idrotm[i+1599], 90., atheta, 90., atheta + 90., 0., 0.);
       
@@ -3211,7 +3197,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the sensitive part of the strips into its mother (ISV1) 
     
     ypos = 0.;
-    for(j = 1; j <= 22; ++j) {
+    for (j = 1; j <= 22; ++j) {
       if (j % 2 == 0) xpos = dbox1[0] - dits[0];
       else            xpos = -dbox1[0] + dits[0];
       zpos = ((j - 1) - 10.) * 3.91 - 1.96;
@@ -3221,7 +3207,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the electronics of the strips into its mother (SSV1) 
     
     ypos = 0.;
-    for(j = 1; j <= 22; ++j) {
+    for (j = 1; j <= 22; ++j) {
       if (j % 2 == 0) xpos = -dsrv[0] + .28;
       else            xpos = -dsrv[0] + .28 - dits[0] * 2. - .03;
       zpos = ((j - 1) - 10.) * 3.91 - 1.96 + .85;
@@ -3249,7 +3235,7 @@ void AliITSv3::CreateGeometry(){
     
     xpos = -dsrv[0] + .47 + TMath::Sqrt(3.) / 6. * 4.2;
     ypos = 0.;
-    for(j = 1; j <= 23; ++j) {
+    for (j = 1; j <= 23; ++j) {
       zpos = ((j - 1) - 10.) * 3.91 - 1.96 - 4.2/2.;
       gMC->Gspos("SFR5", j, "SSV1", xpos, ypos, zpos, 0, "ONLY");
     }
@@ -3286,7 +3272,7 @@ void AliITSv3::CreateGeometry(){
     rzero   = dbox1[0] + 36.6;
     runo    = dbox1[0] * 2. + 36.6 + dsrv[0];
     rtwo    = dbox1[0] * 2. + 36.6 + dela[0];
-    for(i = 1; i <= 32; ++i) {
+    for (i = 1; i <= 32; ++i) {
       atheta = (i-1) * ktwopi * kraddeg / 32. + offset2;
       AliMatrix(idrotm[i+1499], 90., atheta, 90., atheta + 90., 0., 0.);
       
@@ -3468,7 +3454,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the sensitive part of the strips into its mother (ISV2) 
     
     ypos = 0.;
-    for(j = 1; j <= 24; ++j) {
+    for (j = 1; j <= 24; ++j) {
       if (j % 2 == 0) xpos = -dbox2[0] + dits[0];
       else            xpos = dbox2[0] - dits[0];
       zpos = ((j - 1) - 11.) * 3.91 - 1.96;
@@ -3478,7 +3464,7 @@ void AliITSv3::CreateGeometry(){
     // --- Place the electronics of the strips into its mother (SSV2) 
     
     ypos = 0.;
-    for(j = 1; j <= 24; ++j) {
+    for (j = 1; j <= 24; ++j) {
       if (j % 2 == 0) xpos = -dsrv[0] + .28 - dits[0] * 2. - .03;
       else            xpos = -dsrv[0] + .28;
       zpos = ((j - 1) - 11.) * 3.91 - 1.96 + .85;
@@ -3506,7 +3492,7 @@ void AliITSv3::CreateGeometry(){
     
     xpos = -dsrv[0] + .47 + TMath::Sqrt(3.) / 6. * 4.2;
     ypos = 0.;
-    for(j = 1; j <= 25; ++j) {
+    for (j = 1; j <= 25; ++j) {
       zpos = ((j - 1) - 11.) * 3.91 - 1.96 - 4.2/2.;
       gMC->Gspos("SFR6", j, "SSV2", xpos, ypos, zpos, 0, "ONLY");
     }
@@ -3543,7 +3529,7 @@ void AliITSv3::CreateGeometry(){
     rzero   = dbox2[0] + 41.2;
     runo    = dbox2[0] * 2. + 41.2 + dsrv[0];
     rtwo    = dbox2[0] * 2. + 41.2 + dela[0];
-    for(i = 1; i <= 36; ++i) {
+    for (i = 1; i <= 36; ++i) {
       atheta = (i-1) * ktwopi * kraddeg / 36. + offset2;
       AliMatrix(idrotm[i+1599], 90., atheta, 90., atheta + 90., 0., 0.);
       
@@ -3623,7 +3609,7 @@ void AliITSv3::CreateGeometry(){
     dtra1[2] = TMath::Sqrt(dtra[2] * dtra[2] + (55.4*55.4-50.5*50.5))/2.;
     angle    = 45.;
     offset   = angle / 2.;
-    for(i = 0; i < 8; ++i) {
+    for (i = 0; i < 8; ++i) {
       xtra[i] = rzero * TMath::Cos(i * angle * kdegrad);
       ytra[i] = rzero * TMath::Sin(i * angle * kdegrad);
       ztra[i] = 0.;
@@ -3788,7 +3774,7 @@ void AliITSv3::CreateGeometry(){
     dtra1[2] = TMath::Sqrt(dtra[2] * dtra[2] + (55.4*55.4-50.5*50.5))/2.;
     angle    = 45.;
     offset   = angle / 2.;
-    for(i = 0; i < 8; ++i) {
+    for (i = 0; i < 8; ++i) {
       xtra[i] = rzero * TMath::Cos(i * angle * kdegrad);
       ytra[i] = rzero * TMath::Sin(i * angle * kdegrad);
       ztra[i] = 0.;
@@ -3962,7 +3948,7 @@ void AliITSv3::CreateGeometry(){
     dtra4[2] = TMath::Sqrt(dtra2[2] * dtra2[2] + (59.9*59.9-50.*50.)) / 2.;
     angle = 60.;
     offset = angle / 2.;
-    for(i = 0; i < 6; ++i) {
+    for (i = 0; i < 6; ++i) {
       xtra1[i] = rzero * TMath::Cos((i * angle + offset) *kdegrad);
       ytra1[i] = rzero * TMath::Sin((i * angle + offset) *kdegrad);
       ztra1[i] = 0.;
@@ -4195,7 +4181,7 @@ void AliITSv3::CreateGeometry(){
     dtra4[2] = TMath::Sqrt(dtra2[2] * dtra2[2] + (59.9*59.9-50.*50.)) / 2.;
     angle  = 60.;
     offset = angle / 2.;
-    for(i = 0; i < 6; ++i) {
+    for (i = 0; i < 6; ++i) {
       xtra1[i] = rzero * TMath::Cos((i * angle + offset) *kdegrad);
       ytra1[i] = rzero * TMath::Sin((i * angle + offset) *kdegrad);
       ztra1[i] = 0.;
@@ -4922,18 +4908,7 @@ void AliITSv3::Init(){
 ////////////////////////////////////////////////////////////////////////
 //     Initialise the ITS after it has been created.
 ////////////////////////////////////////////////////////////////////////
-    Int_t i,j,l;
 
-    fIdN       = fId3N;;
-    fIdName    = new char*[fIdN];
-    fIdSens    = new Int_t[fIdN];
-    for(i=0;i> fId3N;
-	  //R__b.ReadArray(fId3Name);
       }else{
+	  AliITS::Streamer(R__b);
       } // end if
    } else {
       R__b.WriteVersion(AliITSv3::IsA());
       AliITS::Streamer(R__b);
-      // This information does not need to be saved. It is "hard wired"
-      // into this class via its creators.
-      //R__b << fId3N;
-      //R__b.WriteArray(fId3Name, __COUNTER__);
    } // end if R__b.IsReading()
-    printf("AliITSv3Streamer Finishing\n");
 }
+
+
diff --git a/ITS/AliITSv3.h b/ITS/AliITSv3.h
index e665f6dd3e2..3a352e400da 100644
--- a/ITS/AliITSv3.h
+++ b/ITS/AliITSv3.h
@@ -24,24 +24,18 @@ class AliITSv3 : public AliITS {
     virtual void   CreateMaterials();
     virtual void   Init();   
     virtual Int_t  IsVersion() const {
-	                                   // returns the ITS version number 
-	                                   return 3;
-												 }
+      // returns the ITS version number 
+      return 3;
+    }
     virtual void   SetMinorVersion(Int_t version) {
-	                                                // sets the minor version 
-	                                                fMinorVersionV3=version;
-																   }
+      // sets the minor version 
+      fMinorVersionV3=version;
+    }
     virtual void   StepManager();
 
  protected:
     Int_t fMinorVersionV3;  //Minor version identifier
 
- private:
-    Int_t fId3N; // The number of layers for geometry version 5
-                 // The name of the layers as defined in the Geant tree.
-    char  **fId3Name; // They are the names of the sensitive volumes
-
-
    
     ClassDef(AliITSv3,1)//Hits manager for set:ITS version 3, TP detailed geometry
 };
diff --git a/ITS/AliITSv5.cxx b/ITS/AliITSv5.cxx
index 6f08ae3eba3..443033fb8a7 100644
--- a/ITS/AliITSv5.cxx
+++ b/ITS/AliITSv5.cxx
@@ -15,16 +15,6 @@
 
 /*
 $Log$
-Revision 1.14.4.9  2000/06/12 19:14:51  barbera
-Remove partical transision to new Config.C calling convension. Bug Found.
-
-Revision 1.14.4.8  2000/06/12 18:15:52  barbera
-fixed posible compilation errors on HP unix. Modifided default constructor
-for use with new calling requirements.
-
-Revision 1.14.4.7  2000/06/11 20:37:59  barbera
-coding convenstion update.
-
 Revision 1.14.4.4  2000/05/19 10:10:21  nilsen
 fix for bug with HP and Sun unix + fix for event display in ITS-working branch
 
@@ -91,22 +81,22 @@ Introduction of the Copyright and cvs Log
 ClassImp(AliITSv5)
  
 //_____________________________________________________________________________
-  AliITSv5::AliITSv5()/*:AliITS("ITS","TDR version")*/{
+AliITSv5::AliITSv5() {
 ////////////////////////////////////////////////////////////////////////
 //    Standard default constructor for the ITS version 5.
 ////////////////////////////////////////////////////////////////////////
-    fId5N = 6;
-    fId5Name = new char*[fId5N];
-    fId5Name[0] = "ITS1";
-    fId5Name[1] = "ITS2";
-    fId5Name[2] = "ITS3";
-    fId5Name[3] = "ITS4";
-    fId5Name[4] = "ITS5";
-    fId5Name[5] = "ITS6";
 
-    fEuclidMaterial = "$ALICE_ROOT/Euclid/ITSgeometry_5.tme";
-    fEuclidGeometry = "$ALICE_ROOT/Euclid/ITSgeometry_5.euc";
-    printf("Created ITS TDR Detailed version reading geometry from file\n");
+    fIdN = 6;
+    fIdName = new TString[fIdN];
+    fIdName[0] = "ITS1";
+    fIdName[1] = "ITS2";
+    fIdName[2] = "ITS3";
+    fIdName[3] = "ITS4";
+    fIdName[4] = "ITS5";
+    fIdName[5] = "ITS6";
+    fIdSens    = new Int_t[fIdN];
+    for (Int_t i=0;ifId5N = source.fId5N;
-    this->fId5Name = new char*[fId5N];
-    Int_t i;
-    for(i=0;i<6;i++) strcpy(this->fId5Name[i],source.fId5Name[i]);
+    printf("Not allowed to copy AliITSv5\n");
     return;
 }
 //_____________________________________________________________________________
@@ -125,37 +112,37 @@ AliITSv5& AliITSv5::operator=(const AliITSv5 &source){
 ////////////////////////////////////////////////////////////////////////
 //    Assignment operator for the ITS version 1.
 ////////////////////////////////////////////////////////////////////////
-  if(&source == this) return *this;
-  this->fId5N = source.fId5N;
-  this->fId5Name = new char*[fId5N];
-  Int_t i;
-  for(i=0;i<6;i++) strcpy(this->fId5Name[i],source.fId5Name[i]);
-  return *this;
+
+    if(&source == this) return *this;
+    printf("Not allowed to copy AliITSv3\n");
+    return *this;
+
 }
 //_____________________________________________________________________________
 AliITSv5::~AliITSv5() {
 ////////////////////////////////////////////////////////////////////////
 //    Standard destructor for the ITS version 5.
 ////////////////////////////////////////////////////////////////////////
-  delete [] fId5Name;
 }
 //_____________________________________________________________________________
 AliITSv5::AliITSv5(const char *name, const char *title) : AliITS(name, title){
 ////////////////////////////////////////////////////////////////////////
 //    Standard constructor for the ITS version 5.
 ////////////////////////////////////////////////////////////////////////
-    fId5N = 6;
-    fId5Name = new char*[fId5N];
-    fId5Name[0] = "ITS1";
-    fId5Name[1] = "ITS2";
-    fId5Name[2] = "ITS3";
-    fId5Name[3] = "ITS4";
-    fId5Name[4] = "ITS5";
-    fId5Name[5] = "ITS6";
+    fIdN = 6;
+    fIdName = new TString[fIdN];
+    fIdName[0] = "ITS1";
+    fIdName[1] = "ITS2";
+    fIdName[2] = "ITS3";
+    fIdName[3] = "ITS4";
+    fIdName[4] = "ITS5";
+    fIdName[5] = "ITS6";
+    fIdSens    = new Int_t[fIdN];
+    for (Int_t i=0;iGetGeometry()->GetNode("alice");
   AliITSgeom  *gm = this->GetITSgeom();
@@ -583,17 +570,6 @@ void AliITSv5::Init(){
 ////////////////////////////////////////////////////////////////////////
 //     Initialise the ITS after it has been created.
 ////////////////////////////////////////////////////////////////////////
-    Int_t i,j,l;
-
-    fIdN    = fId5N;
-    fIdName = new char*[fId5N];
-    fIdSens = new Int_t[fId5N];
-    for(i=0;i> fId5N;
-	  //R__b.ReadArray(fId5Name);
       }else{
+	  AliITS::Streamer(R__b);
       } // end if R__v==1
    } else {
       R__b.WriteVersion(AliITSv5::IsA());
       AliITS::Streamer(R__b);
-      // This information does not need to be saved. It is "hard wired"
-      // into this class via its creators.
-      //R__b << fId5N;
-      //R__b.WriteArray(fId5Name, __COUNTER__);
    } // end if R__b.IsReading()
-   //    printf("AliITSv5Streamer Finishing\n");
 }
-
diff --git a/ITS/AliITSv5.h b/ITS/AliITSv5.h
index 1e8bdb1e3af..3bcb5bba526 100644
--- a/ITS/AliITSv5.h
+++ b/ITS/AliITSv5.h
@@ -9,10 +9,8 @@
 //     Manager and hits classes for  ITS version 5
 ////////////////////////////////////////////////////////////////////////
 
-#include "TString.h"
 #include "TBRIK.h"
 #include "AliITS.h"
-#include "AliITSgeom.h"
 
 class AliITSv5 : public AliITS {
 
@@ -27,17 +25,11 @@ class AliITSv5 : public AliITS {
     virtual void  CreateMaterials();
     virtual void  Init();   
     virtual Int_t IsVersion() const {
-	                                  // returns the ITS version number
-	                                  return 5;
-												}
+      // returns the ITS version number
+      return 5;
+    }
     virtual void  StepManager();
 
- private:
-    Int_t fId5N; // The number of layers for geometry version 5
-                 // The name of the layers as defined in the Geant tree.
-    char  **fId5Name; // They are the names of the sensitive volumes
-
-
 
     ClassDef(AliITSv5,1)//Hits manager for ITS version 5 Official detailed geometry
 };
diff --git a/ITS/AliITSvtest.cxx b/ITS/AliITSvtest.cxx
new file mode 100644
index 00000000000..0a032c7545b
--- /dev/null
+++ b/ITS/AliITSvtest.cxx
@@ -0,0 +1,336 @@
+/**************************************************************************
+ * 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/03/02 21:53:36  nilsen
+to make it compatable with the changes in AliRun/AliModule.
+
+Revision 1.1.2.1  2000/01/12 20:19:03  nilsen
+	The changes made with this latest inclusion of code is very large.
+Many of the new files were added just in December when P. Cerello added his
+SDD simulations to the distrobutions. Also added are some file of P. Skowronski
+for SSD cluster finding and ghost RecPoints. None of this "new" code has been
+proporly tested. Other code new to this cvs repository is explained in the
+ITS Off-line web page. In general the changes are too large to give a resonable
+discription of them but probably should be taken as the starting point for
+the developement branch (ITS-working).
+    B. S. Nilsen
+
+Revision 1.13  1999/10/16 19:49:00  BSN
+$Name$
+$Author$
+$Id$
+*/
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+//  Inner Traking System version Test                                        //
+//  This class contains the base procedures for the Inner Tracking System    //
+//                                                                           //
+// Authors: R. Barbera, B. S. Nilsen.                                        //
+// version  Test                                                             //
+// Created October 16 1999.                                                  //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include 
+#include 
+#include 
+
+#include "AliRun.h"
+#include "TSystem.h"
+#include "AliITShit.h"
+#include "AliITS.h"
+#include "AliITSvtest.h"
+#include "AliITSgeom.h"
+
+ClassImp(AliITSvtest)
+ 
+//_____________________________________________________________________________
+AliITSvtest::AliITSvtest() {
+    //
+    // Standard constructor for the ITS
+    //
+/*
+    fIdTestN = 6;
+    fIdTestName = new TString[fIdTestN];
+    fIdTestName[0] = "ITS1";
+    fIdTestName[1] = "ITS2";
+    fIdTestName[2] = "ITS3";
+    fIdTestName[3] = "ITS4";
+    fIdTestName[4] = "ITS5";
+    fIdTestName[5] = "ITS6";
+*/
+}
+//____________________________________________________________________________
+AliITSvtest::AliITSvtest(const AliITSvtest &source){
+////////////////////////////////////////////////////////////////////////
+//     Copy Constructor for ITS test version.
+////////////////////////////////////////////////////////////////////////
+    if(&source == this) return;
+    printf("Not allowed to copy AliITSvtest\n");
+    return;
+}
+//_____________________________________________________________________________
+AliITSvtest& AliITSvtest::operator=(const AliITSvtest &source){
+////////////////////////////////////////////////////////////////////////
+//    Assignment operator for the ITS version 1.
+////////////////////////////////////////////////////////////////////////
+	if(&source == this) return *this;
+	printf("Not allowed to copy AliITSvtest\n");
+	return *this;
+}
+//_____________________________________________________________________________
+AliITSvtest::~AliITSvtest() {
+    //
+    // Standard destructor for the ITS
+    //
+  delete [] fIdTestName;
+}
+//_____________________________________________________________________________
+AliITSvtest::AliITSvtest(const char *fileeuc,const char *filetme,
+			 const char *name, const char *title) 
+    : AliITS(name, title){
+    //
+    // Standard constructor for the ITS
+    //
+    fIdTestN = 6;
+    fIdTestName = new TString[fIdTestN];
+    fIdTestName[0] = "ITS1";
+    fIdTestName[1] = "ITS2";
+    fIdTestName[2] = "ITS3";
+    fIdTestName[3] = "ITS4";
+    fIdTestName[4] = "ITS5";
+    fIdTestName[5] = "ITS6";
+
+    fEuclidMaterial = filetme;
+    fEuclidGeometry = fileeuc;
+//  The .det file for the geometry must have the same name as fileeuc with
+//  .euc replaced by .det.
+}
+
+ 
+//_____________________________________________________________________________
+void AliITSvtest::CreateMaterials(){
+  //
+  // Read materials for the ITS
+  //
+    char *filtmp;
+//
+  filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
+//  FILE *file = fopen(fEuclidMaterial.Data(),"r");
+  FILE *file = fopen(filtmp,"r");
+  if(file) {
+    fclose(file);
+//    ReadEuclidMedia(fEuclidMaterial.Data(),this);
+    ReadEuclidMedia(filtmp);
+  } else {
+    Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",
+//	  fEuclidMaterial.Data());
+	  filtmp);
+    exit(1);
+  } // end if(file)
+}
+
+//_____________________________________________________________________________
+void AliITSvtest::CreateGeometry(){
+//////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+// Read geometry for the ITS
+//
+
+    Int_t size;
+    char topvol[5];
+    char *filtmp;
+//
+  filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
+  FILE *file = fopen(filtmp,"r");
+  delete [] filtmp;
+  if(file) {
+    fclose(file);
+    printf("Ready to read Euclid geometry file\n");
+    ReadEuclid(fEuclidGeometry.Data(),topvol);
+    printf("Read in euclid geometries\n");
+  } else {
+    Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
+	  fEuclidGeometry.Data());
+    exit(1);
+  } // end if(file)
+  //
+  //---Place the ITS ghost volume ITSV in its mother volume (ALIC) and make it
+  //     invisible
+  //
+  gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
+  //
+  //---Outputs the geometry tree in the EUCLID/CAD format
+  
+    if (fEuclidOut) {
+      gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
+    } // end if (fEuclidOut)
+
+    filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
+    size = strlen(filtmp);
+    if(size>4){
+	filtmp[size-3] = 'd'; // change from .euc to .det
+        filtmp[size-2] = 'e';
+        filtmp[size-1] = 't';
+	file = fopen(filtmp,"r");
+	if(file){ // if file exists use it to fill AliITSgeom structure.
+	    fclose(file);
+	    printf("ready to read .det file %s\n",filtmp);
+	    fITSgeom = new AliITSgeom(filtmp);
+	}else{
+	    fITSgeom = 0;
+	    // fill AliITSgeom structure from geant structure just filled above
+	}// end if(file)
+        delete [] filtmp;
+    }// end if(size>4)
+    printf("finished with euclid geometrys\n");
+}
+
+//_____________________________________________________________________________
+void AliITSvtest::Init(){
+    //
+    // Initialise the ITS after it has been created
+    //
+    Int_t i;
+
+    fIdN    = fIdTestN;
+    fIdName = new TString[fIdTestN];
+    fIdSens = new Int_t[fIdTestN];
+    for(i=0;iIsTrackInside())      vol[3] +=  1;
+  if(gMC->IsTrackEntering())    vol[3] +=  2;
+  if(gMC->IsTrackExiting())     vol[3] +=  4;
+  if(gMC->IsTrackOut())         vol[3] +=  8;
+  if(gMC->IsTrackDisappeared()) vol[3] += 16;
+  if(gMC->IsTrackStop())        vol[3] += 32;
+  if(gMC->IsTrackAlive())       vol[3] += 64;
+  //
+  // Fill hit structure.
+  if(!(gMC->TrackCharge())) return;
+  //
+  // Only entering charged tracks
+  if((id = gMC->CurrentVolID(copy)) == fIdSens[0]) {
+      vol[0] = 1;
+      id = gMC->CurrentVolOffID(0,copy);
+      //detector copy in the ladder = 1<->4  (ITS1)
+      vol[1] = copy;
+      gMC->CurrentVolOffID(1,copy1);
+      //ladder copy in the module   = 1<->2  (I186)
+      gMC->CurrentVolOffID(2,copy2);
+      //module copy in the layer    = 1<->10 (I132)
+      vol[2] = copy1+(copy2-1)*2;//# of ladders in one module  = 2
+  } else if(id == fIdSens[1]){
+      vol[0] = 2;
+      id = gMC->CurrentVolOffID(0,copy);
+      //detector copy in the ladder = 1<->4  (ITS2)
+      vol[1] = copy;
+      gMC->CurrentVolOffID(1,copy1);
+      //ladder copy in the module   = 1<->4  (I131)
+      gMC->CurrentVolOffID(2,copy2);
+      //module copy in the layer    = 1<->10 (I132)
+      vol[2] = copy1+(copy2-1)*4;//# of ladders in one module  = 4
+  } else if(id == fIdSens[2]){
+      vol[0] = 3;
+      id = gMC->CurrentVolOffID(1,copy);
+      //detector copy in the ladder = 1<->5  (ITS3 is inside I314)
+      vol[1] = copy;
+      id = gMC->CurrentVolOffID(2,copy);
+      //ladder copy in the layer    = 1<->12 (I316)
+      vol[2] = copy;
+  } else if(id == fIdSens[3]){
+      vol[0] = 4;
+      id = gMC->CurrentVolOffID(1,copy);
+      //detector copy in the ladder = 1<->8  (ITS4 is inside I414)
+      vol[1] = copy;
+      id = gMC->CurrentVolOffID(2,copy);
+      //ladder copy in the layer    = 1<->22 (I417)
+      vol[2] = copy;
+  }else if(id == fIdSens[4]){
+      vol[0] = 5;
+      id = gMC->CurrentVolOffID(1,copy);
+      //detector copy in the ladder = 1<->23  (ITS5 is inside I562)
+      vol[1] = copy;
+      id = gMC->CurrentVolOffID(2,copy);
+     //ladder copy in the layer    = 1<->34 (I565)
+      vol[2] = copy;
+  }else if(id == fIdSens[5]){
+      vol[0] = 6;
+      id = gMC->CurrentVolOffID(1,copy);
+      //detector copy in the ladder = 1<->26  (ITS6 is inside I566)
+      vol[1] = copy;
+      id = gMC->CurrentVolOffID(2,copy);
+      //ladder copy in the layer = 1<->38 (I569)
+      vol[2] = copy;
+  } else {
+      return; // not an ITS volume?
+  } // end if/else if (gMC->CurentVolID(copy) == fIdSens[i])
+//
+  gMC->TrackPosition(position);
+  gMC->TrackMomentum(momentum);
+  hits[0]=position[0];
+  hits[1]=position[1];
+  hits[2]=position[2];
+  hits[3]=momentum[0];
+  hits[4]=momentum[1];
+  hits[5]=momentum[2];
+  hits[6]=gMC->Edep();
+  hits[7]=gMC->TrackTime();
+  // Fill hit structure with this new hit.
+  new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->CurrentTrack(),vol,hits);
+  return;
+}
+//____________________________________________________________________________
+void AliITSvtest::Streamer(TBuffer &R__b)
+{
+   // Stream an object of class AliITSvtest.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      AliITS::Streamer(R__b);
+   } else {
+      R__b.WriteVersion(AliITSvtest::IsA());
+      AliITS::Streamer(R__b);
+   }
+}
+
diff --git a/ITS/AliITSvtest.h b/ITS/AliITSvtest.h
new file mode 100644
index 00000000000..12018dff13a
--- /dev/null
+++ b/ITS/AliITSvtest.h
@@ -0,0 +1,43 @@
+#ifndef ALIITSVTEST_H
+#define ALIITSVTEST_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+////////////////////////////////////////////////////////////////////////
+//     Manager and hits classes for  ITS version 5
+////////////////////////////////////////////////////////////////////////
+
+
+#include "AliITS.h"
+
+class AliITSvtest : public AliITS {
+
+public:
+           AliITSvtest();
+			  AliITSvtest(const char *fileeuc,const char *filetme,
+			  const char *name, const char *title);
+           AliITSvtest(const AliITSvtest &source); // copy constructor
+           AliITSvtest& operator=(const AliITSvtest &source); // assignment operator			  
+           virtual       ~AliITSvtest() ;
+           virtual void  CreateGeometry();
+           virtual void  CreateMaterials();
+           virtual void  Init();
+           virtual Int_t IsVersion() const {
+			                                   // returns the ITS version number 
+			                                   return -1;
+														 }
+           virtual void  StepManager();
+
+private:
+           Int_t fIdTestN; // The number of layers for test geometry version
+                           // The name of the layers as defined in the Geant tree.
+           TString *fIdTestName; // They are the names of the sensitive volumes
+
+
+  
+  ClassDef(AliITSvtest,1)  //Hits manager for ITS test version, Private ITS class for different test geometries
+};
+ 
+#endif
diff --git a/ITS/AlignITSmacro.C b/ITS/AlignITSmacro.C
new file mode 100644
index 00000000000..29a8064a369
--- /dev/null
+++ b/ITS/AlignITSmacro.C
@@ -0,0 +1,110 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;        // data points to fit.
+    Float_t  a,b,c,d,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+};
+
+//
+void AlignITSmacro (const char *filename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and fill some histograms.
+//
+//     Root > .L AlignITS.C    //this loads the macro in memory
+//     Root > AlignITS();  //by default process first event   
+//     Root > AlignITS("galice.root"); //process file galice.root
+//     Root > AlignITS("galice.root",3); // process file galice.root
+//                                          the first 4 eventst
+//       or
+//     Root > .x AlignITS.C;  //by default process first event   
+//     Root > .x AlignITS.C("galice.root"); //process file galice.root
+//     Root > .x AlignITS.C("galice.root",3); // process file galice.root
+//                                               the first 4 eventst
+/////////////////////////////////////////////////////////////////////////
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+      
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+   if(!file) file = new TFile(filename);
+   printf("reading from file %s\n",filename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)file->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+
+      // define some variables for later use.
+      Int_t      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      AliITS *ITS    = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TTree  *TH     = gAlice->TreeH();
+      Int_t  ntracks = TH->GetEntries();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      ClustAl_tl *trk = new ClustAl_tl[ntracks];
+      Int_t      ntrk;
+      Float_t    v0[3] = {0.0,0.0,0.0};
+
+      printf("ntracks=%d\n",ntracks);
+
+      HitsTo(trk,ntrk,ntracks,TH,ITS,sigma1,sigma2,sigma3,0.0,0.0,0.0);
+
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//      return;
+      // setup to save all created histograms.
+      char Hfilename[80];
+      sprintf(Hfilename,"%s.root",sfile);
+      TFile *Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+      if(Hfile) Hfile->Close();
+      Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+      printf("Histograms saved to file %s\n",Hfilename);
+
+      FitAllTracks(trk,ntrk,v0,sfile,Hfile); 
+// fit all tracks and do a track quality hist.
+
+      printf("Fitted tracks, finding vertex next\n");
+
+      FitVertexAll(trk,ntrk,sfile,Hfile); 
+// Find all 2 track vertecies and hist. them.
+
+      printf("Event %d done\n",evnt);
+
+      for(Int_t i=0;i
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   FILE       *fp;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=0;Itimes<1;Itimes++){
+	  if(Itimes==0){
+	      fp = fopen();
+            fprintf(fp,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6");
+	  }else if(Itimes==1){
+	      fp = fopen();
+            fprintf(fp,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6");
+	  }else if(Itimes==2){
+	      fp = fopen();
+            fprintf(fp,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6");
+	  }else if(Itimes==3){
+	      fp = fopen();
+            fprintf(fp,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6");
+	  }else if(Itimes==4){
+	      fp = fopen();
+            fprintf(fp,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6");
+	  }else if(Itimes==5){
+	      fp = fopen();
+            fprintf(fp,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+                            "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6")
+	  } // end if
+	  for(Isigmas=0;Isigmas<11;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fp = fclose();
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AlignITSmacro3.C b/ITS/AlignITSmacro3.C
new file mode 100644
index 00000000000..03913a5bde2
--- /dev/null
+++ b/ITS/AlignITSmacro3.C
@@ -0,0 +1,266 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#include 
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   Float_t    Rdta[6];
+   Float_t    Fdta[24],Fdta0[24];
+   Int_t      Ndta[12];
+   FILE       *fp1,*fp2;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=1;Itimes<2;Itimes++){
+	  if(Itimes==0){
+	      fp1 = fopen("RvariationsR.csv","w");
+	      fp2 = fopen("RvariationsN.csv","w");
+            fprintf(fp1,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6");
+            fprintf(fp2,"Rr,Rs,RN1,RN2,RN3,RN4,RN5,RN6,RN7,RN8,RN9,RN10,"
+		    "RN50,Rcut");
+	  }else if(Itimes==1){
+	      fp1 = fopen("RPhivariationsR.csv","w");
+	      fp2 = fopen("RPhivariationsN.csv","w");
+            fprintf(fp1,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6");
+            fprintf(fp2,"Fr,Fs,FN1,FN2,FN3,FN4,FN5,FN6,FN7,FN8,FN9,FN10,"
+		    "FN50,Fcut");
+	  }else if(Itimes==2){
+	      fp1 = fopen("ZvariationsR.csv","w");
+	      fp2 = fopen("ZvariationsN.csv","w");
+            fprintf(fp1,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6");
+            fprintf(fp2,"Zr,Zs,ZN1,ZN2,ZN3,ZN4,ZN5,ZN6,ZN7,ZN8,ZN9,ZN10,"
+		    "ZN50,Zcut");
+	  }else if(Itimes==3){
+	      fp1 = fopen("AvariationsR.csv","w");
+	      fp2 = fopen("AvariationsN.csv","w");
+            fprintf(fp1,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6");
+            fprintf(fp2,"Ar,As,AN1,AN2,AN3,AN4,AN5,AN6,AN7,AN8,AN9,AN10,"
+		    "AN50,Acut");
+	  }else if(Itimes==4){
+	      fp1 = fopen("BvariationsR.csv","w");
+	      fp2 = fopen("BvariationsN.csv","w");
+            fprintf(fp1,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6");
+            fprintf(fp2,"Br,Bs,BN1,BN2,BN3,BN4,BN5,BN6,BN7,BN8,BN9,BN10,"
+		    "BN50,Bcut");
+	  }else if(Itimes==5){
+	      fp1 = fopen("CvariationsR.csv","w");
+	      fp2 = fopen("CvariationsN.csv","w");
+            fprintf(fp1,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+		    "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6");
+            fprintf(fp2,"Cr,Cs,CN1,CN2,CN3,CN4,CN5,CN6,CN7,CN8,CN9,CN10,"
+		    "CN50,Ccut");
+	  } // end if
+	  fprintf(fp1,"\n");
+	  fprintf(fp2,"\n");
+	  for(Isigmas=0;Isigmas<15;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile,Fdta,Ndta); 
+//
+	  if(Isigmas==0){
+	      for(Int_t fp=0;fp<24;fp++) Fdta0[fp] = Fdta[fp];
+	  } // end if Itimes==0&&Isigmas==0
+	  if(Itimes==0) fprintf(fp1,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp1,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp1,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp1,"%e,%e,",ran[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp1,"%e,%e,",ran[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp1,"%e,%e,",ran[2],Rdta[5]);
+	  if(Itimes==0) fprintf(fp2,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp2,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp2,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp2,"%e,%e,",ran[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp2,"%e,%e,",ran[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp2,"%e,%e,",ran[2],Rdta[5]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[0],Fdta[1],Fdta[0]/Fdta0[0],Fdta[0]/Fdta0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[2],Fdta[3],Fdta[2]/Fdta0[2],Fdta[3]/Fdta0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[4],Fdta[5],Fdta[4]/Fdta0[4],Fdta[5]/Fdta0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[6],Fdta[7],Fdta[6]/Fdta0[6],Fdta[7]/Fdta0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[8],Fdta[9],Fdta[8]/Fdta0[8],Fdta[9]/Fdta0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[10],Fdta[11],Fdta[10]/Fdta0[10],Fdta[11]/Fdta0[10]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[12],Fdta[12],Fdta[12]/Fdta0[12],Fdta[13]/Fdta0[12]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[14],Fdta[13],Fdta[14]/Fdta0[14],Fdta[15]/Fdta0[14]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[16],Fdta[15],Fdta[16]/Fdta0[16],Fdta[17]/Fdta0[16]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[18],Fdta[17],Fdta[18]/Fdta0[18],Fdta[19]/Fdta0[18]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[20],Fdta[19],Fdta[20]/Fdta0[20],Fdta[21]/Fdta0[20]);
+	  fprintf(fp1,"%e,%e,%e,%e\n",Fdta[22],Fdta[21],Fdta[22]/Fdta0[22],Fdta[23]/Fdta0[22]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[0],Ndta[1],Ndta[2],Ndta[3]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[4],Ndta[5],Ndta[6],Ndta[7]);
+	  fprintf(fp2,"%d,%d,%d,%d\n",Ndta[8],Ndta[9],Ndta[10],Ndta[11]);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fclose(fp1);
+	  fclose(fp2);
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AlignITSmacro3A.C b/ITS/AlignITSmacro3A.C
new file mode 100644
index 00000000000..f20a75530ba
--- /dev/null
+++ b/ITS/AlignITSmacro3A.C
@@ -0,0 +1,319 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#include 
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3A(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   Float_t    Rdta[6];
+   Float_t    Fdta[24],Fdr[12],Fdta0[24],Fdr0[12];
+   Int_t      Ndta[12];
+   FILE       *fp1,*fp2;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=3;Itimes<4;Itimes++){
+	  if(Itimes==0){
+	      fp1 = fopen("RvariationsR.csv","w");
+	      fp2 = fopen("RvariationsN.csv","w");
+            fprintf(fp1,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		    "Rrd1,Rerd1,Rsrd1,Resrd1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		    "Rrd2,Rerd2,Rsrd2,Resrd2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+		    "Rrd3,Rerd3,Rsrd3,Resrd3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+		    "Rrd4,Rerd4,Rsrd4,Resrd4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+		    "Rrd5,Rerd5,Rsrd5,Resrd5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6,"
+		    "Rrd6,Rerd6,Rsrd6,Resrd6");
+            fprintf(fp2,"Rr,Rs,RN1,RN2,RN3,RN4,RN5,RN6,RN7,RN8,RN9,RN10,"
+		    "RN50,Rcut");
+	  }else if(Itimes==1){
+	      fp1 = fopen("RPhivariationsR.csv","w");
+	      fp2 = fopen("RPhivariationsN.csv","w");
+            fprintf(fp1,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		    "Frd1,Ferd1,Fsrd1,Fesrd1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		    "Frd2,Ferd2,Fsrd2,Fesrd2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+		    "Frd3,Ferd3,Fsrd3,Fesrd3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+		    "Frd4,Ferd4,Fsrd4,Fesrd4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+		    "Frd5,Ferd5,Fsrd5,Fesrd5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6,"
+		    "Frd6,Ferd6,Fsrd6,Fesrd6");
+            fprintf(fp2,"Fr,Fs,FN1,FN2,FN3,FN4,FN5,FN6,FN7,FN8,FN9,FN10,"
+		    "FN50,Fcut");
+	  }else if(Itimes==2){
+	      fp1 = fopen("ZvariationsR.csv","w");
+	      fp2 = fopen("ZvariationsN.csv","w");
+            fprintf(fp1,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		    "Zrd1,Zerd1,Zsrd1,Zesrd1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		    "Zrd2,Zerd2,Zsrd2,Zesrd2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+		    "Zrd3,Zerd3,Zsrd3,Zesrd3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+		    "Zrd4,Zerd4,Zsrd4,Zesrd4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+		    "Zrd5,Zerd5,Zsrd5,Zesrd5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6,"
+		    "Zrd6,Zerd6,Zsrd6,Zesrd6");
+            fprintf(fp2,"Zr,Zs,ZN1,ZN2,ZN3,ZN4,ZN5,ZN6,ZN7,ZN8,ZN9,ZN10,"
+		    "ZN50,Zcut");
+	  }else if(Itimes==3){
+	      fp1 = fopen("AvariationsR.csv","w");
+	      fp2 = fopen("AvariationsN.csv","w");
+            fprintf(fp1,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		    "Ard1,Aerd1,Asrd1,Aesrd1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		    "Ard2,Aerd2,Asrd2,Aesrd2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+		    "Ard3,Aerd3,Asrd3,Aesrd3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+		    "Ard4,Aerd4,Asrd4,Aesrd4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+		    "Ard5,Aerd5,Asrd5,Aesrd5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6,"
+		    "Ard6,Aerd6,Asrd6,Aesrd6");
+            fprintf(fp2,"Ar,As,AN1,AN2,AN3,AN4,AN5,AN6,AN7,AN8,AN9,AN10,"
+		    "AN50,Acut");
+	  }else if(Itimes==4){
+	      fp1 = fopen("BvariationsR.csv","w");
+	      fp2 = fopen("BvariationsN.csv","w");
+            fprintf(fp1,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		    "Brd1,Berd1,Bsrd1,Besrd1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		    "Brd2,Berd2,Bsrd2,Besrd2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+		    "Brd3,Berd3,Bsrd3,Besrd3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+		    "Brd4,Berd4,Bsrd4,Besrd4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+		    "Brd5,Berd5,Bsrd5,Besrd5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6,"
+		    "Brd6,Berd6,Bsrd6,Besrd6");
+            fprintf(fp2,"Br,Bs,BN1,BN2,BN3,BN4,BN5,BN6,BN7,BN8,BN9,BN10,"
+		    "BN50,Bcut");
+	  }else if(Itimes==5){
+	      fp1 = fopen("CvariationsR.csv","w");
+	      fp2 = fopen("CvariationsN.csv","w");
+            fprintf(fp1,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		    "Crd1,Cerd1,Csrd1,Cesrd1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		    "Crd2,Cerd2,Csrd2,Cesrd2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+		    "Crd3,Cerd3,Csrd3,Cesrd3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+		    "Crd4,Cerd4,Csrd4,Cesrd4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+		    "Crd5,Cerd5,Csrd5,Cesrd5,"
+		    "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6,"
+		    "Crd6,Cerd6,Csrd6,Cesrd6");
+            fprintf(fp2,"Cr,Cs,CN1,CN2,CN3,CN4,CN5,CN6,CN7,CN8,CN9,CN10,"
+		    "CN50,Ccut");
+	  } // end if
+	  fprintf(fp1,"\n");
+	  fprintf(fp2,"\n");
+	  for(Isigmas=0;Isigmas<15;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile,Fdta,Ndta); 
+//
+	  for(Int_t l=0;l<6;l++){
+	      Fdr[2*l+0] = sqrt(Fdta[4*l+0]*Fdta[4*l+0] +
+				Fdta[4*l+2]*Fdta[4*l+2]);
+	      Fdr[2*l+1] = sqrt(Fdta[4*l+0]*Fdta[4*l+0]*
+				Fdta[4*l+1]*Fdta[4*l+1] +
+				Fdta[4*l+2]*Fdta[4*l+2]*
+				Fdta[4*l+3]*Fdta[4*l+3])/Fdr[2*l+0];
+	  } // end for l
+	  if(Isigmas==0){
+	      for(Int_t fp=0;fp<24;fp++){
+		  Fdta0[fp] = Fdta[fp];
+		  if(fp<12) Fdr0[fp]  = Fdr[fp];
+	      } // end for fp
+	  } // end if Itimes==0&&Isigmas==0
+	  if(Itimes==0) fprintf(fp1,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp1,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp1,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp1,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp1,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp1,"%e,%e,",rot[2],Rdta[5]);
+	  if(Itimes==0) fprintf(fp2,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp2,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp2,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp2,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp2,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp2,"%e,%e,",rot[2],Rdta[5]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[0],Fdta[1],Fdta[0]/Fdta0[0],Fdta[1]/Fdta0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[2],Fdta[3],Fdta[2]/Fdta0[2],Fdta[3]/Fdta0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[0],Fdr[1],Fdr[0]/Fdr0[0],Fdr[1]/Fdr0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[4],Fdta[5],Fdta[4]/Fdta0[4],Fdta[5]/Fdta0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[6],Fdta[7],Fdta[6]/Fdta0[6],Fdta[7]/Fdta0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[2],Fdr[3],Fdr[2]/Fdr0[2],Fdr[3]/Fdr0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[8],Fdta[9],Fdta[8]/Fdta0[8],Fdta[9]/Fdta0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[10],Fdta[11],Fdta[10]/Fdta0[10],Fdta[11]/Fdta0[10]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[4],Fdr[5],Fdr[4]/Fdr0[4],Fdr[5]/Fdr0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[12],Fdta[12],Fdta[12]/Fdta0[12],Fdta[13]/Fdta0[12]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[14],Fdta[13],Fdta[14]/Fdta0[14],Fdta[15]/Fdta0[14]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[6],Fdr[7],Fdr[6]/Fdr0[6],Fdr[7]/Fdr0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[16],Fdta[15],Fdta[16]/Fdta0[16],Fdta[17]/Fdta0[16]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[18],Fdta[17],Fdta[18]/Fdta0[18],Fdta[19]/Fdta0[18]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[8],Fdr[9],Fdr[8]/Fdr0[8],Fdr[9]/Fdr0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[20],Fdta[19],Fdta[20]/Fdta0[20],Fdta[21]/Fdta0[20]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[22],Fdta[21],Fdta[22]/Fdta0[22],Fdta[23]/Fdta0[22]);
+	  fprintf(fp1,"%e,%e,%e,%e\n",Fdr[10],Fdr[11],Fdr[10]/Fdr0[10],Fdr[11]/Fdr0[10]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[0],Ndta[1],Ndta[2],Ndta[3]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[4],Ndta[5],Ndta[6],Ndta[7]);
+	  fprintf(fp2,"%d,%d,%d,%d\n",Ndta[8],Ndta[9],Ndta[10],Ndta[11]);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fclose(fp1);
+	  fclose(fp2);
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AlignITSmacro3B.C b/ITS/AlignITSmacro3B.C
new file mode 100644
index 00000000000..e3840cf2182
--- /dev/null
+++ b/ITS/AlignITSmacro3B.C
@@ -0,0 +1,319 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#include 
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3B(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   Float_t    Rdta[6];
+   Float_t    Fdta[24],Fdr[12],Fdta0[24],Fdr0[12];
+   Int_t      Ndta[12];
+   FILE       *fp1,*fp2;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=4;Itimes<5;Itimes++){
+	  if(Itimes==0){
+	      fp1 = fopen("RvariationsR.csv","w");
+	      fp2 = fopen("RvariationsN.csv","w");
+            fprintf(fp1,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		    "Rrd1,Rerd1,Rsrd1,Resrd1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		    "Rrd2,Rerd2,Rsrd2,Resrd2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+		    "Rrd3,Rerd3,Rsrd3,Resrd3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+		    "Rrd4,Rerd4,Rsrd4,Resrd4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+		    "Rrd5,Rerd5,Rsrd5,Resrd5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6,"
+		    "Rrd6,Rerd6,Rsrd6,Resrd6");
+            fprintf(fp2,"Rr,Rs,RN1,RN2,RN3,RN4,RN5,RN6,RN7,RN8,RN9,RN10,"
+		    "RN50,Rcut");
+	  }else if(Itimes==1){
+	      fp1 = fopen("RPhivariationsR.csv","w");
+	      fp2 = fopen("RPhivariationsN.csv","w");
+            fprintf(fp1,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		    "Frd1,Ferd1,Fsrd1,Fesrd1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		    "Frd2,Ferd2,Fsrd2,Fesrd2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+		    "Frd3,Ferd3,Fsrd3,Fesrd3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+		    "Frd4,Ferd4,Fsrd4,Fesrd4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+		    "Frd5,Ferd5,Fsrd5,Fesrd5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6,"
+		    "Frd6,Ferd6,Fsrd6,Fesrd6");
+            fprintf(fp2,"Fr,Fs,FN1,FN2,FN3,FN4,FN5,FN6,FN7,FN8,FN9,FN10,"
+		    "FN50,Fcut");
+	  }else if(Itimes==2){
+	      fp1 = fopen("ZvariationsR.csv","w");
+	      fp2 = fopen("ZvariationsN.csv","w");
+            fprintf(fp1,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		    "Zrd1,Zerd1,Zsrd1,Zesrd1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		    "Zrd2,Zerd2,Zsrd2,Zesrd2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+		    "Zrd3,Zerd3,Zsrd3,Zesrd3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+		    "Zrd4,Zerd4,Zsrd4,Zesrd4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+		    "Zrd5,Zerd5,Zsrd5,Zesrd5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6,"
+		    "Zrd6,Zerd6,Zsrd6,Zesrd6");
+            fprintf(fp2,"Zr,Zs,ZN1,ZN2,ZN3,ZN4,ZN5,ZN6,ZN7,ZN8,ZN9,ZN10,"
+		    "ZN50,Zcut");
+	  }else if(Itimes==3){
+	      fp1 = fopen("AvariationsR.csv","w");
+	      fp2 = fopen("AvariationsN.csv","w");
+            fprintf(fp1,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		    "Ard1,Aerd1,Asrd1,Aesrd1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		    "Ard2,Aerd2,Asrd2,Aesrd2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+		    "Ard3,Aerd3,Asrd3,Aesrd3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+		    "Ard4,Aerd4,Asrd4,Aesrd4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+		    "Ard5,Aerd5,Asrd5,Aesrd5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6,"
+		    "Ard6,Aerd6,Asrd6,Aesrd6");
+            fprintf(fp2,"Ar,As,AN1,AN2,AN3,AN4,AN5,AN6,AN7,AN8,AN9,AN10,"
+		    "AN50,Acut");
+	  }else if(Itimes==4){
+	      fp1 = fopen("BvariationsR.csv","w");
+	      fp2 = fopen("BvariationsN.csv","w");
+            fprintf(fp1,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		    "Brd1,Berd1,Bsrd1,Besrd1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		    "Brd2,Berd2,Bsrd2,Besrd2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+		    "Brd3,Berd3,Bsrd3,Besrd3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+		    "Brd4,Berd4,Bsrd4,Besrd4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+		    "Brd5,Berd5,Bsrd5,Besrd5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6,"
+		    "Brd6,Berd6,Bsrd6,Besrd6");
+            fprintf(fp2,"Br,Bs,BN1,BN2,BN3,BN4,BN5,BN6,BN7,BN8,BN9,BN10,"
+		    "BN50,Bcut");
+	  }else if(Itimes==5){
+	      fp1 = fopen("CvariationsR.csv","w");
+	      fp2 = fopen("CvariationsN.csv","w");
+            fprintf(fp1,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		    "Crd1,Cerd1,Csrd1,Cesrd1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		    "Crd2,Cerd2,Csrd2,Cesrd2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+		    "Crd3,Cerd3,Csrd3,Cesrd3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+		    "Crd4,Cerd4,Csrd4,Cesrd4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+		    "Crd5,Cerd5,Csrd5,Cesrd5,"
+		    "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6,"
+		    "Crd6,Cerd6,Csrd6,Cesrd6");
+            fprintf(fp2,"Cr,Cs,CN1,CN2,CN3,CN4,CN5,CN6,CN7,CN8,CN9,CN10,"
+		    "CN50,Ccut");
+	  } // end if
+	  fprintf(fp1,"\n");
+	  fprintf(fp2,"\n");
+	  for(Isigmas=0;Isigmas<15;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile,Fdta,Ndta); 
+//
+	  for(Int_t l=0;l<6;l++){
+	      Fdr[2*l+0] = sqrt(Fdta[4*l+0]*Fdta[4*l+0] +
+				Fdta[4*l+2]*Fdta[4*l+2]);
+	      Fdr[2*l+1] = sqrt(Fdta[4*l+0]*Fdta[4*l+0]*
+				Fdta[4*l+1]*Fdta[4*l+1] +
+				Fdta[4*l+2]*Fdta[4*l+2]*
+				Fdta[4*l+3]*Fdta[4*l+3])/Fdr[2*l+0];
+	  } // end for l
+	  if(Isigmas==0){
+	      for(Int_t fp=0;fp<24;fp++){
+		  Fdta0[fp] = Fdta[fp];
+		  if(fp<12) Fdr0[fp]  = Fdr[fp];
+	      } // end for fp
+	  } // end if Itimes==0&&Isigmas==0
+	  if(Itimes==0) fprintf(fp1,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp1,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp1,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp1,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp1,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp1,"%e,%e,",rot[2],Rdta[5]);
+	  if(Itimes==0) fprintf(fp2,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp2,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp2,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp2,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp2,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp2,"%e,%e,",rot[2],Rdta[5]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[0],Fdta[1],Fdta[0]/Fdta0[0],Fdta[1]/Fdta0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[2],Fdta[3],Fdta[2]/Fdta0[2],Fdta[3]/Fdta0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[0],Fdr[1],Fdr[0]/Fdr0[0],Fdr[1]/Fdr0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[4],Fdta[5],Fdta[4]/Fdta0[4],Fdta[5]/Fdta0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[6],Fdta[7],Fdta[6]/Fdta0[6],Fdta[7]/Fdta0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[2],Fdr[3],Fdr[2]/Fdr0[2],Fdr[3]/Fdr0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[8],Fdta[9],Fdta[8]/Fdta0[8],Fdta[9]/Fdta0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[10],Fdta[11],Fdta[10]/Fdta0[10],Fdta[11]/Fdta0[10]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[4],Fdr[5],Fdr[4]/Fdr0[4],Fdr[5]/Fdr0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[12],Fdta[12],Fdta[12]/Fdta0[12],Fdta[13]/Fdta0[12]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[14],Fdta[13],Fdta[14]/Fdta0[14],Fdta[15]/Fdta0[14]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[6],Fdr[7],Fdr[6]/Fdr0[6],Fdr[7]/Fdr0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[16],Fdta[15],Fdta[16]/Fdta0[16],Fdta[17]/Fdta0[16]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[18],Fdta[17],Fdta[18]/Fdta0[18],Fdta[19]/Fdta0[18]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[8],Fdr[9],Fdr[8]/Fdr0[8],Fdr[9]/Fdr0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[20],Fdta[19],Fdta[20]/Fdta0[20],Fdta[21]/Fdta0[20]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[22],Fdta[21],Fdta[22]/Fdta0[22],Fdta[23]/Fdta0[22]);
+	  fprintf(fp1,"%e,%e,%e,%e\n",Fdr[10],Fdr[11],Fdr[10]/Fdr0[10],Fdr[11]/Fdr0[10]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[0],Ndta[1],Ndta[2],Ndta[3]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[4],Ndta[5],Ndta[6],Ndta[7]);
+	  fprintf(fp2,"%d,%d,%d,%d\n",Ndta[8],Ndta[9],Ndta[10],Ndta[11]);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fclose(fp1);
+	  fclose(fp2);
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AlignITSmacro3C.C b/ITS/AlignITSmacro3C.C
new file mode 100644
index 00000000000..fd6b672ca1e
--- /dev/null
+++ b/ITS/AlignITSmacro3C.C
@@ -0,0 +1,319 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#include 
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3C(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   Float_t    Rdta[6];
+   Float_t    Fdta[24],Fdr[12],Fdta0[24],Fdr0[12];
+   Int_t      Ndta[12];
+   FILE       *fp1,*fp2;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=5;Itimes<6;Itimes++){
+	  if(Itimes==0){
+	      fp1 = fopen("RvariationsR.csv","w");
+	      fp2 = fopen("RvariationsN.csv","w");
+            fprintf(fp1,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		    "Rrd1,Rerd1,Rsrd1,Resrd1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		    "Rrd2,Rerd2,Rsrd2,Resrd2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+		    "Rrd3,Rerd3,Rsrd3,Resrd3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+		    "Rrd4,Rerd4,Rsrd4,Resrd4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+		    "Rrd5,Rerd5,Rsrd5,Resrd5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6,"
+		    "Rrd6,Rerd6,Rsrd6,Resrd6");
+            fprintf(fp2,"Rr,Rs,RN1,RN2,RN3,RN4,RN5,RN6,RN7,RN8,RN9,RN10,"
+		    "RN50,Rcut");
+	  }else if(Itimes==1){
+	      fp1 = fopen("RPhivariationsR.csv","w");
+	      fp2 = fopen("RPhivariationsN.csv","w");
+            fprintf(fp1,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		    "Frd1,Ferd1,Fsrd1,Fesrd1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		    "Frd2,Ferd2,Fsrd2,Fesrd2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+		    "Frd3,Ferd3,Fsrd3,Fesrd3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+		    "Frd4,Ferd4,Fsrd4,Fesrd4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+		    "Frd5,Ferd5,Fsrd5,Fesrd5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6,"
+		    "Frd6,Ferd6,Fsrd6,Fesrd6");
+            fprintf(fp2,"Fr,Fs,FN1,FN2,FN3,FN4,FN5,FN6,FN7,FN8,FN9,FN10,"
+		    "FN50,Fcut");
+	  }else if(Itimes==2){
+	      fp1 = fopen("ZvariationsR.csv","w");
+	      fp2 = fopen("ZvariationsN.csv","w");
+            fprintf(fp1,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		    "Zrd1,Zerd1,Zsrd1,Zesrd1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		    "Zrd2,Zerd2,Zsrd2,Zesrd2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+		    "Zrd3,Zerd3,Zsrd3,Zesrd3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+		    "Zrd4,Zerd4,Zsrd4,Zesrd4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+		    "Zrd5,Zerd5,Zsrd5,Zesrd5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6,"
+		    "Zrd6,Zerd6,Zsrd6,Zesrd6");
+            fprintf(fp2,"Zr,Zs,ZN1,ZN2,ZN3,ZN4,ZN5,ZN6,ZN7,ZN8,ZN9,ZN10,"
+		    "ZN50,Zcut");
+	  }else if(Itimes==3){
+	      fp1 = fopen("AvariationsR.csv","w");
+	      fp2 = fopen("AvariationsN.csv","w");
+            fprintf(fp1,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		    "Ard1,Aerd1,Asrd1,Aesrd1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		    "Ard2,Aerd2,Asrd2,Aesrd2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+		    "Ard3,Aerd3,Asrd3,Aesrd3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+		    "Ard4,Aerd4,Asrd4,Aesrd4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+		    "Ard5,Aerd5,Asrd5,Aesrd5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6,"
+		    "Ard6,Aerd6,Asrd6,Aesrd6");
+            fprintf(fp2,"Ar,As,AN1,AN2,AN3,AN4,AN5,AN6,AN7,AN8,AN9,AN10,"
+		    "AN50,Acut");
+	  }else if(Itimes==4){
+	      fp1 = fopen("BvariationsR.csv","w");
+	      fp2 = fopen("BvariationsN.csv","w");
+            fprintf(fp1,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		    "Brd1,Berd1,Bsrd1,Besrd1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		    "Brd2,Berd2,Bsrd2,Besrd2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+		    "Brd3,Berd3,Bsrd3,Besrd3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+		    "Brd4,Berd4,Bsrd4,Besrd4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+		    "Brd5,Berd5,Bsrd5,Besrd5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6,"
+		    "Brd6,Berd6,Bsrd6,Besrd6");
+            fprintf(fp2,"Br,Bs,BN1,BN2,BN3,BN4,BN5,BN6,BN7,BN8,BN9,BN10,"
+		    "BN50,Bcut");
+	  }else if(Itimes==5){
+	      fp1 = fopen("CvariationsR.csv","w");
+	      fp2 = fopen("CvariationsN.csv","w");
+            fprintf(fp1,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		    "Crd1,Cerd1,Csrd1,Cesrd1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		    "Crd2,Cerd2,Csrd2,Cesrd2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+		    "Crd3,Cerd3,Csrd3,Cesrd3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+		    "Crd4,Cerd4,Csrd4,Cesrd4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+		    "Crd5,Cerd5,Csrd5,Cesrd5,"
+		    "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6,"
+		    "Crd6,Cerd6,Csrd6,Cesrd6");
+            fprintf(fp2,"Cr,Cs,CN1,CN2,CN3,CN4,CN5,CN6,CN7,CN8,CN9,CN10,"
+		    "CN50,Ccut");
+	  } // end if
+	  fprintf(fp1,"\n");
+	  fprintf(fp2,"\n");
+	  for(Isigmas=0;Isigmas<15;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile,Fdta,Ndta); 
+//
+	  for(Int_t l=0;l<6;l++){
+	      Fdr[2*l+0] = sqrt(Fdta[4*l+0]*Fdta[4*l+0] +
+				Fdta[4*l+2]*Fdta[4*l+2]);
+	      Fdr[2*l+1] = sqrt(Fdta[4*l+0]*Fdta[4*l+0]*
+				Fdta[4*l+1]*Fdta[4*l+1] +
+				Fdta[4*l+2]*Fdta[4*l+2]*
+				Fdta[4*l+3]*Fdta[4*l+3])/Fdr[2*l+0];
+	  } // end for l
+	  if(Isigmas==0){
+	      for(Int_t fp=0;fp<24;fp++){
+		  Fdta0[fp] = Fdta[fp];
+		  if(fp<12) Fdr0[fp]  = Fdr[fp];
+	      } // end for fp
+	  } // end if Itimes==0&&Isigmas==0
+	  if(Itimes==0) fprintf(fp1,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp1,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp1,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp1,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp1,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp1,"%e,%e,",rot[2],Rdta[5]);
+	  if(Itimes==0) fprintf(fp2,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp2,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp2,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp2,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp2,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp2,"%e,%e,",rot[2],Rdta[5]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[0],Fdta[1],Fdta[0]/Fdta0[0],Fdta[1]/Fdta0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[2],Fdta[3],Fdta[2]/Fdta0[2],Fdta[3]/Fdta0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[0],Fdr[1],Fdr[0]/Fdr0[0],Fdr[1]/Fdr0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[4],Fdta[5],Fdta[4]/Fdta0[4],Fdta[5]/Fdta0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[6],Fdta[7],Fdta[6]/Fdta0[6],Fdta[7]/Fdta0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[2],Fdr[3],Fdr[2]/Fdr0[2],Fdr[3]/Fdr0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[8],Fdta[9],Fdta[8]/Fdta0[8],Fdta[9]/Fdta0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[10],Fdta[11],Fdta[10]/Fdta0[10],Fdta[11]/Fdta0[10]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[4],Fdr[5],Fdr[4]/Fdr0[4],Fdr[5]/Fdr0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[12],Fdta[12],Fdta[12]/Fdta0[12],Fdta[13]/Fdta0[12]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[14],Fdta[13],Fdta[14]/Fdta0[14],Fdta[15]/Fdta0[14]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[6],Fdr[7],Fdr[6]/Fdr0[6],Fdr[7]/Fdr0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[16],Fdta[15],Fdta[16]/Fdta0[16],Fdta[17]/Fdta0[16]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[18],Fdta[17],Fdta[18]/Fdta0[18],Fdta[19]/Fdta0[18]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[8],Fdr[9],Fdr[8]/Fdr0[8],Fdr[9]/Fdr0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[20],Fdta[19],Fdta[20]/Fdta0[20],Fdta[21]/Fdta0[20]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[22],Fdta[21],Fdta[22]/Fdta0[22],Fdta[23]/Fdta0[22]);
+	  fprintf(fp1,"%e,%e,%e,%e\n",Fdr[10],Fdr[11],Fdr[10]/Fdr0[10],Fdr[11]/Fdr0[10]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[0],Ndta[1],Ndta[2],Ndta[3]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[4],Ndta[5],Ndta[6],Ndta[7]);
+	  fprintf(fp2,"%d,%d,%d,%d\n",Ndta[8],Ndta[9],Ndta[10],Ndta[11]);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fclose(fp1);
+	  fclose(fp2);
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AlignITSmacro3R.C b/ITS/AlignITSmacro3R.C
new file mode 100644
index 00000000000..0afb9dec461
--- /dev/null
+++ b/ITS/AlignITSmacro3R.C
@@ -0,0 +1,319 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#include 
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3R(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   Float_t    Rdta[6];
+   Float_t    Fdta[24],Fdr[12],Fdta0[24],Fdr0[12];
+   Int_t      Ndta[12];
+   FILE       *fp1,*fp2;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=0;Itimes<1;Itimes++){
+	  if(Itimes==0){
+	      fp1 = fopen("RvariationsR.csv","w");
+	      fp2 = fopen("RvariationsN.csv","w");
+            fprintf(fp1,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		    "Rrd1,Rerd1,Rsrd1,Resrd1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		    "Rrd2,Rerd2,Rsrd2,Resrd2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+		    "Rrd3,Rerd3,Rsrd3,Resrd3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+		    "Rrd4,Rerd4,Rsrd4,Resrd4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+		    "Rrd5,Rerd5,Rsrd5,Resrd5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6,"
+		    "Rrd6,Rerd6,Rsrd6,Resrd6");
+            fprintf(fp2,"Rr,Rs,RN1,RN2,RN3,RN4,RN5,RN6,RN7,RN8,RN9,RN10,"
+		    "RN50,Rcut");
+	  }else if(Itimes==1){
+	      fp1 = fopen("RPhivariationsR.csv","w");
+	      fp2 = fopen("RPhivariationsN.csv","w");
+            fprintf(fp1,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		    "Frd1,Ferd1,Fsrd1,Fesrd1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		    "Frd2,Ferd2,Fsrd2,Fesrd2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+		    "Frd3,Ferd3,Fsrd3,Fesrd3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+		    "Frd4,Ferd4,Fsrd4,Fesrd4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+		    "Frd5,Ferd5,Fsrd5,Fesrd5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6,"
+		    "Frd6,Ferd6,Fsrd6,Fesrd6");
+            fprintf(fp2,"Fr,Fs,FN1,FN2,FN3,FN4,FN5,FN6,FN7,FN8,FN9,FN10,"
+		    "FN50,Fcut");
+	  }else if(Itimes==2){
+	      fp1 = fopen("ZvariationsR.csv","w");
+	      fp2 = fopen("ZvariationsN.csv","w");
+            fprintf(fp1,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		    "Zrd1,Zerd1,Zsrd1,Zesrd1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		    "Zrd2,Zerd2,Zsrd2,Zesrd2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+		    "Zrd3,Zerd3,Zsrd3,Zesrd3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+		    "Zrd4,Zerd4,Zsrd4,Zesrd4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+		    "Zrd5,Zerd5,Zsrd5,Zesrd5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6,"
+		    "Zrd6,Zerd6,Zsrd6,Zesrd6");
+            fprintf(fp2,"Zr,Zs,ZN1,ZN2,ZN3,ZN4,ZN5,ZN6,ZN7,ZN8,ZN9,ZN10,"
+		    "ZN50,Zcut");
+	  }else if(Itimes==3){
+	      fp1 = fopen("AvariationsR.csv","w");
+	      fp2 = fopen("AvariationsN.csv","w");
+            fprintf(fp1,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		    "Ard1,Aerd1,Asrd1,Aesrd1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		    "Ard2,Aerd2,Asrd2,Aesrd2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+		    "Ard3,Aerd3,Asrd3,Aesrd3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+		    "Ard4,Aerd4,Asrd4,Aesrd4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+		    "Ard5,Aerd5,Asrd5,Aesrd5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6,"
+		    "Ard6,Aerd6,Asrd6,Aesrd6");
+            fprintf(fp2,"Ar,As,AN1,AN2,AN3,AN4,AN5,AN6,AN7,AN8,AN9,AN10,"
+		    "AN50,Acut");
+	  }else if(Itimes==4){
+	      fp1 = fopen("BvariationsR.csv","w");
+	      fp2 = fopen("BvariationsN.csv","w");
+            fprintf(fp1,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		    "Brd1,Berd1,Bsrd1,Besrd1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		    "Brd2,Berd2,Bsrd2,Besrd2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+		    "Brd3,Berd3,Bsrd3,Besrd3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+		    "Brd4,Berd4,Bsrd4,Besrd4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+		    "Brd5,Berd5,Bsrd5,Besrd5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6,"
+		    "Brd6,Berd6,Bsrd6,Besrd6");
+            fprintf(fp2,"Br,Bs,BN1,BN2,BN3,BN4,BN5,BN6,BN7,BN8,BN9,BN10,"
+		    "BN50,Bcut");
+	  }else if(Itimes==5){
+	      fp1 = fopen("CvariationsR.csv","w");
+	      fp2 = fopen("CvariationsN.csv","w");
+            fprintf(fp1,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		    "Crd1,Cerd1,Csrd1,Cesrd1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		    "Crd2,Cerd2,Csrd2,Cesrd2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+		    "Crd3,Cerd3,Csrd3,Cesrd3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+		    "Crd4,Cerd4,Csrd4,Cesrd4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+		    "Crd5,Cerd5,Csrd5,Cesrd5,"
+		    "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6,"
+		    "Crd6,Cerd6,Csrd6,Cesrd6");
+            fprintf(fp2,"Cr,Cs,CN1,CN2,CN3,CN4,CN5,CN6,CN7,CN8,CN9,CN10,"
+		    "CN50,Ccut");
+	  } // end if
+	  fprintf(fp1,"\n");
+	  fprintf(fp2,"\n");
+	  for(Isigmas=0;Isigmas<15;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile,Fdta,Ndta); 
+//
+	  for(Int_t l=0;l<6;l++){
+	      Fdr[2*l+0] = sqrt(Fdta[4*l+0]*Fdta[4*l+0] +
+				Fdta[4*l+2]*Fdta[4*l+2]);
+	      Fdr[2*l+1] = sqrt(Fdta[4*l+0]*Fdta[4*l+0]*
+				Fdta[4*l+1]*Fdta[4*l+1] +
+				Fdta[4*l+2]*Fdta[4*l+2]*
+				Fdta[4*l+3]*Fdta[4*l+3])/Fdr[2*l+0];
+	  } // end for l
+	  if(Isigmas==0){
+	      for(Int_t fp=0;fp<24;fp++){
+		  Fdta0[fp] = Fdta[fp];
+		  if(fp<12) Fdr0[fp]  = Fdr[fp];
+	      } // end for fp
+	  } // end if Itimes==0&&Isigmas==0
+	  if(Itimes==0) fprintf(fp1,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp1,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp1,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp1,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp1,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp1,"%e,%e,",rot[2],Rdta[5]);
+	  if(Itimes==0) fprintf(fp2,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp2,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp2,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp2,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp2,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp2,"%e,%e,",rot[2],Rdta[5]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[0],Fdta[1],Fdta[0]/Fdta0[0],Fdta[1]/Fdta0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[2],Fdta[3],Fdta[2]/Fdta0[2],Fdta[3]/Fdta0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[0],Fdr[1],Fdr[0]/Fdr0[0],Fdr[1]/Fdr0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[4],Fdta[5],Fdta[4]/Fdta0[4],Fdta[5]/Fdta0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[6],Fdta[7],Fdta[6]/Fdta0[6],Fdta[7]/Fdta0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[2],Fdr[3],Fdr[2]/Fdr0[2],Fdr[3]/Fdr0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[8],Fdta[9],Fdta[8]/Fdta0[8],Fdta[9]/Fdta0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[10],Fdta[11],Fdta[10]/Fdta0[10],Fdta[11]/Fdta0[10]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[4],Fdr[5],Fdr[4]/Fdr0[4],Fdr[5]/Fdr0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[12],Fdta[12],Fdta[12]/Fdta0[12],Fdta[13]/Fdta0[12]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[14],Fdta[13],Fdta[14]/Fdta0[14],Fdta[15]/Fdta0[14]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[6],Fdr[7],Fdr[6]/Fdr0[6],Fdr[7]/Fdr0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[16],Fdta[15],Fdta[16]/Fdta0[16],Fdta[17]/Fdta0[16]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[18],Fdta[17],Fdta[18]/Fdta0[18],Fdta[19]/Fdta0[18]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[8],Fdr[9],Fdr[8]/Fdr0[8],Fdr[9]/Fdr0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[20],Fdta[19],Fdta[20]/Fdta0[20],Fdta[21]/Fdta0[20]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[22],Fdta[21],Fdta[22]/Fdta0[22],Fdta[23]/Fdta0[22]);
+	  fprintf(fp1,"%e,%e,%e,%e\n",Fdr[10],Fdr[11],Fdr[10]/Fdr0[10],Fdr[11]/Fdr0[10]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[0],Ndta[1],Ndta[2],Ndta[3]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[4],Ndta[5],Ndta[6],Ndta[7]);
+	  fprintf(fp2,"%d,%d,%d,%d\n",Ndta[8],Ndta[9],Ndta[10],Ndta[11]);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fclose(fp1);
+	  fclose(fp2);
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AlignITSmacro3Rphi.C b/ITS/AlignITSmacro3Rphi.C
new file mode 100644
index 00000000000..4ae176e22fa
--- /dev/null
+++ b/ITS/AlignITSmacro3Rphi.C
@@ -0,0 +1,319 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#include 
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3Rphi(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   Float_t    Rdta[6];
+   Float_t    Fdta[24],Fdr[12],Fdta0[24],Fdr0[12];
+   Int_t      Ndta[12];
+   FILE       *fp1,*fp2;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=1;Itimes<2;Itimes++){
+	  if(Itimes==0){
+	      fp1 = fopen("RvariationsR.csv","w");
+	      fp2 = fopen("RvariationsN.csv","w");
+            fprintf(fp1,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		    "Rrd1,Rerd1,Rsrd1,Resrd1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		    "Rrd2,Rerd2,Rsrd2,Resrd2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+		    "Rrd3,Rerd3,Rsrd3,Resrd3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+		    "Rrd4,Rerd4,Rsrd4,Resrd4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+		    "Rrd5,Rerd5,Rsrd5,Resrd5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6,"
+		    "Rrd6,Rerd6,Rsrd6,Resrd6");
+            fprintf(fp2,"Rr,Rs,RN1,RN2,RN3,RN4,RN5,RN6,RN7,RN8,RN9,RN10,"
+		    "RN50,Rcut");
+	  }else if(Itimes==1){
+	      fp1 = fopen("RPhivariationsR.csv","w");
+	      fp2 = fopen("RPhivariationsN.csv","w");
+            fprintf(fp1,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		    "Frd1,Ferd1,Fsrd1,Fesrd1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		    "Frd2,Ferd2,Fsrd2,Fesrd2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+		    "Frd3,Ferd3,Fsrd3,Fesrd3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+		    "Frd4,Ferd4,Fsrd4,Fesrd4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+		    "Frd5,Ferd5,Fsrd5,Fesrd5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6,"
+		    "Frd6,Ferd6,Fsrd6,Fesrd6");
+            fprintf(fp2,"Fr,Fs,FN1,FN2,FN3,FN4,FN5,FN6,FN7,FN8,FN9,FN10,"
+		    "FN50,Fcut");
+	  }else if(Itimes==2){
+	      fp1 = fopen("ZvariationsR.csv","w");
+	      fp2 = fopen("ZvariationsN.csv","w");
+            fprintf(fp1,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		    "Zrd1,Zerd1,Zsrd1,Zesrd1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		    "Zrd2,Zerd2,Zsrd2,Zesrd2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+		    "Zrd3,Zerd3,Zsrd3,Zesrd3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+		    "Zrd4,Zerd4,Zsrd4,Zesrd4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+		    "Zrd5,Zerd5,Zsrd5,Zesrd5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6,"
+		    "Zrd6,Zerd6,Zsrd6,Zesrd6");
+            fprintf(fp2,"Zr,Zs,ZN1,ZN2,ZN3,ZN4,ZN5,ZN6,ZN7,ZN8,ZN9,ZN10,"
+		    "ZN50,Zcut");
+	  }else if(Itimes==3){
+	      fp1 = fopen("AvariationsR.csv","w");
+	      fp2 = fopen("AvariationsN.csv","w");
+            fprintf(fp1,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		    "Ard1,Aerd1,Asrd1,Aesrd1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		    "Ard2,Aerd2,Asrd2,Aesrd2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+		    "Ard3,Aerd3,Asrd3,Aesrd3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+		    "Ard4,Aerd4,Asrd4,Aesrd4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+		    "Ard5,Aerd5,Asrd5,Aesrd5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6,"
+		    "Ard6,Aerd6,Asrd6,Aesrd6");
+            fprintf(fp2,"Ar,As,AN1,AN2,AN3,AN4,AN5,AN6,AN7,AN8,AN9,AN10,"
+		    "AN50,Acut");
+	  }else if(Itimes==4){
+	      fp1 = fopen("BvariationsR.csv","w");
+	      fp2 = fopen("BvariationsN.csv","w");
+            fprintf(fp1,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		    "Brd1,Berd1,Bsrd1,Besrd1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		    "Brd2,Berd2,Bsrd2,Besrd2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+		    "Brd3,Berd3,Bsrd3,Besrd3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+		    "Brd4,Berd4,Bsrd4,Besrd4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+		    "Brd5,Berd5,Bsrd5,Besrd5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6,"
+		    "Brd6,Berd6,Bsrd6,Besrd6");
+            fprintf(fp2,"Br,Bs,BN1,BN2,BN3,BN4,BN5,BN6,BN7,BN8,BN9,BN10,"
+		    "BN50,Bcut");
+	  }else if(Itimes==5){
+	      fp1 = fopen("CvariationsR.csv","w");
+	      fp2 = fopen("CvariationsN.csv","w");
+            fprintf(fp1,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		    "Crd1,Cerd1,Csrd1,Cesrd1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		    "Crd2,Cerd2,Csrd2,Cesrd2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+		    "Crd3,Cerd3,Csrd3,Cesrd3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+		    "Crd4,Cerd4,Csrd4,Cesrd4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+		    "Crd5,Cerd5,Csrd5,Cesrd5,"
+		    "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6,"
+		    "Crd6,Cerd6,Csrd6,Cesrd6");
+            fprintf(fp2,"Cr,Cs,CN1,CN2,CN3,CN4,CN5,CN6,CN7,CN8,CN9,CN10,"
+		    "CN50,Ccut");
+	  } // end if
+	  fprintf(fp1,"\n");
+	  fprintf(fp2,"\n");
+	  for(Isigmas=0;Isigmas<15;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile,Fdta,Ndta); 
+//
+	  for(Int_t l=0;l<6;l++){
+	      Fdr[2*l+0] = sqrt(Fdta[4*l+0]*Fdta[4*l+0] +
+				Fdta[4*l+2]*Fdta[4*l+2]);
+	      Fdr[2*l+1] = sqrt(Fdta[4*l+0]*Fdta[4*l+0]*
+				Fdta[4*l+1]*Fdta[4*l+1] +
+				Fdta[4*l+2]*Fdta[4*l+2]*
+				Fdta[4*l+3]*Fdta[4*l+3])/Fdr[2*l+0];
+	  } // end for l
+	  if(Isigmas==0){
+	      for(Int_t fp=0;fp<24;fp++){
+		  Fdta0[fp] = Fdta[fp];
+		  if(fp<12) Fdr0[fp]  = Fdr[fp];
+	      } // end for fp
+	  } // end if Itimes==0&&Isigmas==0
+	  if(Itimes==0) fprintf(fp1,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp1,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp1,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp1,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp1,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp1,"%e,%e,",rot[2],Rdta[5]);
+	  if(Itimes==0) fprintf(fp2,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp2,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp2,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp2,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp2,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp2,"%e,%e,",rot[2],Rdta[5]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[0],Fdta[1],Fdta[0]/Fdta0[0],Fdta[1]/Fdta0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[2],Fdta[3],Fdta[2]/Fdta0[2],Fdta[3]/Fdta0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[0],Fdr[1],Fdr[0]/Fdr0[0],Fdr[1]/Fdr0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[4],Fdta[5],Fdta[4]/Fdta0[4],Fdta[5]/Fdta0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[6],Fdta[7],Fdta[6]/Fdta0[6],Fdta[7]/Fdta0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[2],Fdr[3],Fdr[2]/Fdr0[2],Fdr[3]/Fdr0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[8],Fdta[9],Fdta[8]/Fdta0[8],Fdta[9]/Fdta0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[10],Fdta[11],Fdta[10]/Fdta0[10],Fdta[11]/Fdta0[10]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[4],Fdr[5],Fdr[4]/Fdr0[4],Fdr[5]/Fdr0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[12],Fdta[12],Fdta[12]/Fdta0[12],Fdta[13]/Fdta0[12]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[14],Fdta[13],Fdta[14]/Fdta0[14],Fdta[15]/Fdta0[14]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[6],Fdr[7],Fdr[6]/Fdr0[6],Fdr[7]/Fdr0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[16],Fdta[15],Fdta[16]/Fdta0[16],Fdta[17]/Fdta0[16]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[18],Fdta[17],Fdta[18]/Fdta0[18],Fdta[19]/Fdta0[18]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[8],Fdr[9],Fdr[8]/Fdr0[8],Fdr[9]/Fdr0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[20],Fdta[19],Fdta[20]/Fdta0[20],Fdta[21]/Fdta0[20]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[22],Fdta[21],Fdta[22]/Fdta0[22],Fdta[23]/Fdta0[22]);
+	  fprintf(fp1,"%e,%e,%e,%e\n",Fdr[10],Fdr[11],Fdr[10]/Fdr0[10],Fdr[11]/Fdr0[10]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[0],Ndta[1],Ndta[2],Ndta[3]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[4],Ndta[5],Ndta[6],Ndta[7]);
+	  fprintf(fp2,"%d,%d,%d,%d\n",Ndta[8],Ndta[9],Ndta[10],Ndta[11]);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fclose(fp1);
+	  fclose(fp2);
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AlignITSmacro3Z.C b/ITS/AlignITSmacro3Z.C
new file mode 100644
index 00000000000..97147a52fda
--- /dev/null
+++ b/ITS/AlignITSmacro3Z.C
@@ -0,0 +1,319 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#include 
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;      // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+bz and y=c+dz;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+//
+void AlignITSmacro3Z(const char *Rfilename="galice_ITS_B0.root",
+		    const char *sfile="Align_ITS_B0",
+		    Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
+		    Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro illustrating how to 
+//   read the output of GALICE and fill some histograms.
+//
+//     Root > .L AlignITSmacro2.C    // this loads the macro in memory
+//     Root > AlignITSmacro2();      // by default process first event   
+//     Root > AlignITSmacro2("galice.root");   // process file galice.root
+//     Root > AlignITSmacro2("galice.root",3); // process file galice.root
+//                                                the first 4 events
+//       or
+//     Root > .x AlignITSmacro2.C;  //by default process first event
+//     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
+//     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
+//                                                     the first 4 events
+/////////////////////////////////////////////////////////////////////////
+//
+    gROOT->Reset();  // Reset root to it's default state
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+   // Connect the Root Galice file containing Geometry, Kine and Clusts
+   TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
+   if(!Rfile) Rfile = new TFile(Rfilename);
+   printf("reading from file %s\n",Rfilename);
+
+   // Get AliRun object from file or create it if not on file
+   if(!gAlice) {
+      gAlice = (AliRun*)Rfile->Get("gAlice");
+      if( gAlice) printf("AliRun object found on file\n");
+      if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   } /* end if gAlice */
+
+   Float_t    v0[3] = {0.0,0.0,0.0};
+   Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+   Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
+   AliITS     *ITS = 0;
+   TTree      *TH = 0;
+   AliITSgeom *gm,gm2;
+   char       Hfilename[80];
+//   char       Gfilename[80];
+   TFile      *Hfile = 0;
+   ClustAl_tl *trk = 0;
+   Float_t    Rdta[6];
+   Float_t    Fdta[24],Fdr[12],Fdta0[24],Fdr0[12];
+   Int_t      Ndta[12];
+   FILE       *fp1,*fp2;
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+      // define some variables for later use.
+      nparticles = gAlice->GetEvent(evnt);
+      printf("nparticles %d\n",nparticles);
+      if (nparticles <= 0) continue; /* get next event */
+
+      // Get pointers to Alice detectors and Clusts containers
+      ITS   = (AliITS*)gAlice->GetDetector("ITS");
+      if(!ITS) return;          /* error no ITS data exit */
+      TH    = gAlice->TreeH();
+      Ntrkp = TH->GetEntries();
+      gm    = ITS->GetITSgeom();
+
+      // Array (stucture) of clusts for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      trk = new ClustAl_tl[Ntrkp];
+
+      printf("Ntrkp=%d\n",Ntrkp);
+
+      HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
+      printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
+//
+      for(Itimes=2;Itimes<3;Itimes++){
+	  if(Itimes==0){
+	      fp1 = fopen("RvariationsR.csv","w");
+	      fp2 = fopen("RvariationsN.csv","w");
+            fprintf(fp1,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
+		    "Rrd1,Rerd1,Rsrd1,Resrd1,"
+		             "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
+		    "Rrd2,Rerd2,Rsrd2,Resrd2,"
+		             "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
+		    "Rrd3,Rerd3,Rsrd3,Resrd3,"
+	                     "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
+		    "Rrd4,Rerd4,Rsrd4,Resrd4,"
+	                     "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
+		    "Rrd5,Rerd5,Rsrd5,Resrd5,"
+                            "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6,"
+		    "Rrd6,Rerd6,Rsrd6,Resrd6");
+            fprintf(fp2,"Rr,Rs,RN1,RN2,RN3,RN4,RN5,RN6,RN7,RN8,RN9,RN10,"
+		    "RN50,Rcut");
+	  }else if(Itimes==1){
+	      fp1 = fopen("RPhivariationsR.csv","w");
+	      fp2 = fopen("RPhivariationsN.csv","w");
+            fprintf(fp1,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
+		    "Frd1,Ferd1,Fsrd1,Fesrd1,"
+		             "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
+		    "Frd2,Ferd2,Fsrd2,Fesrd2,"
+		             "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
+		    "Frd3,Ferd3,Fsrd3,Fesrd3,"
+	                     "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
+		    "Frd4,Ferd4,Fsrd4,Fesrd4,"
+	                     "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
+		    "Frd5,Ferd5,Fsrd5,Fesrd5,"
+                            "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6,"
+		    "Frd6,Ferd6,Fsrd6,Fesrd6");
+            fprintf(fp2,"Fr,Fs,FN1,FN2,FN3,FN4,FN5,FN6,FN7,FN8,FN9,FN10,"
+		    "FN50,Fcut");
+	  }else if(Itimes==2){
+	      fp1 = fopen("ZvariationsR.csv","w");
+	      fp2 = fopen("ZvariationsN.csv","w");
+            fprintf(fp1,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
+		    "Zrd1,Zerd1,Zsrd1,Zesrd1,"
+		             "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
+		    "Zrd2,Zerd2,Zsrd2,Zesrd2,"
+		             "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
+		    "Zrd3,Zerd3,Zsrd3,Zesrd3,"
+	                     "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
+		    "Zrd4,Zerd4,Zsrd4,Zesrd4,"
+	                     "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
+		    "Zrd5,Zerd5,Zsrd5,Zesrd5,"
+                            "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6,"
+		    "Zrd6,Zerd6,Zsrd6,Zesrd6");
+            fprintf(fp2,"Zr,Zs,ZN1,ZN2,ZN3,ZN4,ZN5,ZN6,ZN7,ZN8,ZN9,ZN10,"
+		    "ZN50,Zcut");
+	  }else if(Itimes==3){
+	      fp1 = fopen("AvariationsR.csv","w");
+	      fp2 = fopen("AvariationsN.csv","w");
+            fprintf(fp1,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
+		    "Ard1,Aerd1,Asrd1,Aesrd1,"
+		             "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
+		    "Ard2,Aerd2,Asrd2,Aesrd2,"
+		             "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
+		    "Ard3,Aerd3,Asrd3,Aesrd3,"
+	                     "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
+		    "Ard4,Aerd4,Asrd4,Aesrd4,"
+	                     "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
+		    "Ard5,Aerd5,Asrd5,Aesrd5,"
+                            "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6,"
+		    "Ard6,Aerd6,Asrd6,Aesrd6");
+            fprintf(fp2,"Ar,As,AN1,AN2,AN3,AN4,AN5,AN6,AN7,AN8,AN9,AN10,"
+		    "AN50,Acut");
+	  }else if(Itimes==4){
+	      fp1 = fopen("BvariationsR.csv","w");
+	      fp2 = fopen("BvariationsN.csv","w");
+            fprintf(fp1,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
+		    "Brd1,Berd1,Bsrd1,Besrd1,"
+		             "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
+		    "Brd2,Berd2,Bsrd2,Besrd2,"
+		             "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
+		    "Brd3,Berd3,Bsrd3,Besrd3,"
+	                     "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
+		    "Brd4,Berd4,Bsrd4,Besrd4,"
+	                     "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
+		    "Brd5,Berd5,Bsrd5,Besrd5,"
+                            "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6,"
+		    "Brd6,Berd6,Bsrd6,Besrd6");
+            fprintf(fp2,"Br,Bs,BN1,BN2,BN3,BN4,BN5,BN6,BN7,BN8,BN9,BN10,"
+		    "BN50,Bcut");
+	  }else if(Itimes==5){
+	      fp1 = fopen("CvariationsR.csv","w");
+	      fp2 = fopen("CvariationsN.csv","w");
+            fprintf(fp1,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
+		    "Crd1,Cerd1,Csrd1,Cesrd1,"
+		             "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
+		    "Crd2,Cerd2,Csrd2,Cesrd2,"
+		             "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
+		    "Crd3,Cerd3,Csrd3,Cesrd3,"
+	                     "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
+		    "Crd4,Cerd4,Csrd4,Cesrd4,"
+	                     "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
+		    "Crd5,Cerd5,Csrd5,Cesrd5,"
+		    "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6,"
+		    "Crd6,Cerd6,Csrd6,Cesrd6");
+            fprintf(fp2,"Cr,Cs,CN1,CN2,CN3,CN4,CN5,CN6,CN7,CN8,CN9,CN10,"
+		    "CN50,Ccut");
+	  } // end if
+	  fprintf(fp1,"\n");
+	  fprintf(fp2,"\n");
+	  for(Isigmas=0;Isigmas<15;Isigmas++){
+//
+//	  tran[0] = sigma1;
+//	  tran[1] = sigma2;
+//	  tran[2] = sigma3;
+	  if(Itimes==0){ tran[0] = trans[Isigmas];
+	  }else tran[0] = 0.0;
+	  if(Itimes==1){ tran[1] = trans[Isigmas];
+	  }else tran[1] = 0.0;
+	  if(Itimes==2){ tran[2] = trans[Isigmas];
+	  }else tran[2] = 0.0;
+	  if(Itimes==3){ rot[0] = rots[Isigmas];
+	  }else rot[0] = 0.0;
+	  if(Itimes==4){ rot[1] = rots[Isigmas];
+	  }else rot[1] = 0.0;
+	  if(Itimes==5){ rot[2] = rots[Isigmas];
+	  }else rot[2] = 0.0;
+	  printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+		 tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	  gm2 = *gm;
+	  gm2.RandomCylindericalChange(tran,rot);
+
+	  FillGlobalPositions(trk,ntrk,&gm2);
+	  // setup to save all created histograms.
+	  sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
+		  sfile,
+		  10000.*tran[0],10000.*tran[1],10000.*tran[2],
+		  10000.* rot[0],10000.* rot[1],10000.* rot[2]);
+	  Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
+	  if(Hfile) Hfile->Close();
+	  Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
+	  printf("Histograms saved to file %s\n",Hfilename);
+          //
+	  PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+          //
+	  // fit all tracks and do a track quality hist.
+	  FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile,Fdta,Ndta); 
+//
+	  for(Int_t l=0;l<6;l++){
+	      Fdr[2*l+0] = sqrt(Fdta[4*l+0]*Fdta[4*l+0] +
+				Fdta[4*l+2]*Fdta[4*l+2]);
+	      Fdr[2*l+1] = sqrt(Fdta[4*l+0]*Fdta[4*l+0]*
+				Fdta[4*l+1]*Fdta[4*l+1] +
+				Fdta[4*l+2]*Fdta[4*l+2]*
+				Fdta[4*l+3]*Fdta[4*l+3])/Fdr[2*l+0];
+	  } // end for l
+	  if(Isigmas==0){
+	      for(Int_t fp=0;fp<24;fp++){
+		  Fdta0[fp] = Fdta[fp];
+		  if(fp<12) Fdr0[fp]  = Fdr[fp];
+	      } // end for fp
+	  } // end if Itimes==0&&Isigmas==0
+	  if(Itimes==0) fprintf(fp1,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp1,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp1,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp1,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp1,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp1,"%e,%e,",rot[2],Rdta[5]);
+	  if(Itimes==0) fprintf(fp2,"%e,%e,",tran[0],Rdta[0]);
+	  else if(Itimes==1) fprintf(fp2,"%e,%e,",tran[1],Rdta[1]);
+	  else if(Itimes==2) fprintf(fp2,"%e,%e,",tran[2],Rdta[2]);
+	  else if(Itimes==3) fprintf(fp2,"%e,%e,",rot[0],Rdta[3]);
+	  else if(Itimes==4) fprintf(fp2,"%e,%e,",rot[1],Rdta[4]);
+	  else if(Itimes==5) fprintf(fp2,"%e,%e,",rot[2],Rdta[5]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[0],Fdta[1],Fdta[0]/Fdta0[0],Fdta[1]/Fdta0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[2],Fdta[3],Fdta[2]/Fdta0[2],Fdta[3]/Fdta0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[0],Fdr[1],Fdr[0]/Fdr0[0],Fdr[1]/Fdr0[0]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[4],Fdta[5],Fdta[4]/Fdta0[4],Fdta[5]/Fdta0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[6],Fdta[7],Fdta[6]/Fdta0[6],Fdta[7]/Fdta0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[2],Fdr[3],Fdr[2]/Fdr0[2],Fdr[3]/Fdr0[2]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[8],Fdta[9],Fdta[8]/Fdta0[8],Fdta[9]/Fdta0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[10],Fdta[11],Fdta[10]/Fdta0[10],Fdta[11]/Fdta0[10]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[4],Fdr[5],Fdr[4]/Fdr0[4],Fdr[5]/Fdr0[4]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[12],Fdta[12],Fdta[12]/Fdta0[12],Fdta[13]/Fdta0[12]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[14],Fdta[13],Fdta[14]/Fdta0[14],Fdta[15]/Fdta0[14]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[6],Fdr[7],Fdr[6]/Fdr0[6],Fdr[7]/Fdr0[6]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[16],Fdta[15],Fdta[16]/Fdta0[16],Fdta[17]/Fdta0[16]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[18],Fdta[17],Fdta[18]/Fdta0[18],Fdta[19]/Fdta0[18]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdr[8],Fdr[9],Fdr[8]/Fdr0[8],Fdr[9]/Fdr0[8]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[20],Fdta[19],Fdta[20]/Fdta0[20],Fdta[21]/Fdta0[20]);
+	  fprintf(fp1,"%e,%e,%e,%e,",Fdta[22],Fdta[21],Fdta[22]/Fdta0[22],Fdta[23]/Fdta0[22]);
+	  fprintf(fp1,"%e,%e,%e,%e\n",Fdr[10],Fdr[11],Fdr[10]/Fdr0[10],Fdr[11]/Fdr0[10]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[0],Ndta[1],Ndta[2],Ndta[3]);
+	  fprintf(fp2,"%d,%d,%d,%d,",Ndta[4],Ndta[5],Ndta[6],Ndta[7]);
+	  fprintf(fp2,"%d,%d,%d,%d\n",Ndta[8],Ndta[9],Ndta[10],Ndta[11]);
+//	  FitVertexAll(trk,ntrk,sfile,Hfile); 
+	  // Find all 2 track vertecies and hist. them.
+	  Hfile->Close();
+          //
+      } // end for Isigmas
+	  fclose(fp1);
+	  fclose(fp2);
+      } // end for Itimes
+//
+      printf("Event %d done\n",evnt);
+//
+      deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
+                               // inside HitsToclustAl.
+      delete[] trk;            // now delet memory allocated above.
+   } // end for evnt
+   Rfile->Close();
+   return;
+}
diff --git a/ITS/AnalysisITSAlignment.cxx b/ITS/AnalysisITSAlignment.cxx
new file mode 100644
index 00000000000..3aae9673105
--- /dev/null
+++ b/ITS/AnalysisITSAlignment.cxx
@@ -0,0 +1,1695 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "AliITS.h"
+#include "TTree.h"
+#include "TClonesArray.h"
+#include "TProfile.h"
+#include "TH2.h"
+#include "TArray.h"
+#include "TRandom.h"
+#include "TCanvas.h"
+#include "TFile.h"
+#include "TParticle.h"
+#include "AliRun.h"
+#include "AliITSgeom.h"
+#include "AnalysisITSAlignment.h"
+#include "AliITSstatistics2.h"
+#include "AliITSstatistics.h"
+#include "AliITSAlignmentTrack.h"
+#include "AliITSAlignmentModule.h"
+
+#define PRIMARYONLY 0  // if PIMARY_ONLY ==0 then all tracks
+#define MOMENTUMCUT 1.0 // Sets the momentum cut for the tracks.
+
+//Double_t resz[]={0.00680,0.00650,0.00265,0.00265,0.0830,0.0830};
+//Double_t resx[]={0.00105,0.00115,0.00340,0.00340,0.0020,0.0020};
+// From table 1.3 of ITS TDR. Spatial precisions and Cell size
+Double_t  resz[]={0.00700,0.00700,0.00280,0.00280,0.08300,0.08300};
+Double_t  resx[]={0.00120,0.00120,0.00380,0.00380,0.00200,0.00200};
+Double_t cellx[]={0.00500,0.00500,0.01500,0.01500,0.00950,0.00950};
+Double_t celly[]={0.00150,0.00150,0.00300,0.00300,0.00300,0.00300};
+Double_t cellz[]={0.03000,0.03000,0.03000,0.03000,4.00000,4.00000};
+
+//_________________________________________________________________________
+void HitsTo(ClustAl_tl *trk,Int_t &ntrk,Int_t nt,TTree *TH,AliITS *ITS,
+	    Float_t nsigmaT1,Float_t nsigmaT2,Float_t nsigmaT3,
+	    Float_t nsigmaR1,Float_t nsigmaR2,Float_t nsigmaR3){
+
+   // Local variables
+   Int_t        nClustMin = 3;
+   const Int_t  jmax = 50;
+   Int_t        t,nb,nh,h,i,ly=-1,ld=-1,dt=-1,tt=-1,j=0;
+   ClustAl_sl   ht[jmax];
+   Int_t        id[3],ie[3],nht[jmax],track;
+   Float_t      gp[3],lp[3],p[3],tof,gp2[3];
+   Float_t      ns;
+   Float_t      px[jmax],py[jmax],pz[jmax];
+   TClonesArray *ITShits = ITS->Hits();
+   AliITShit    *itsHit;
+   // initilize and creat AliITSgeom data
+   AliITSgeom   *gm  = ITS->GetITSgeom();
+   AliITSgeom   &gm2 = *gm;
+
+//   nt = 100; // lets speed things up.
+
+   Float_t tran[]={90.e-4/3.,30.e-4/3.,780.e-4/3.}; // r,rphi,z
+   Float_t  rot[]={0.4e-3/3.,3.0e-3/3.,100.e-3/3.}; // about r, rphi, z
+   tran[0] *= nsigmaT1;
+   tran[1] *= nsigmaT2;
+   tran[2] *= nsigmaT3;
+   rot[0]  *= nsigmaR1;
+   rot[1]  *= nsigmaR2;
+   rot[2]  *= nsigmaR3;
+
+   printf("Randomize by tran=%fcm %fcm %fcm\n",tran[0],tran[1],tran[2]);
+   printf("Randomize by rot=%frad %frad %frad\n",rot[0],rot[1],rot[2]);
+
+   gm2.RandomCylindericalChange(tran,rot);
+
+   for(i=0;iResetHits();
+      nb = TH->GetEvent(t);
+      nh = ITShits->GetEntriesFast();
+      for(h=0;hUncheckedAt(h);
+	 track  = itsHit->fTrack;
+	 if(track != tt){ // if new track
+	     if(j>nClustMin)if(ttzl rphi->xl yl-> thickness leave it alone
+		     lp[0] = lp[0]/resx[ie[0]-1];
+		     lp[0] = (Float_t)((Int_t)lp[0]);
+		     lp[0] = lp[0]*resx[ie[0]-1] + 0.5*resx[ie[0]-1];
+		     lp[2] = lp[2]/resz[ie[0]-1];
+		     lp[2] = (Float_t)((Int_t)lp[2]);
+		     lp[2] = lp[2]*resz[ie[0]-1] + 0.5*resz[ie[0]-1];
+		     //
+		     trk[ntrk].clust[i].xl  = lp[0];
+		     trk[ntrk].clust[i].yl  = lp[1];
+		     trk[ntrk].clust[i].zl  = lp[2];
+		     gm2.LtoG(ie,lp,gp);
+		     gm->LtoG(ie,lp,gp2);
+		     trk[ntrk].clust[i].xg  = gp[0];
+		     trk[ntrk].clust[i].yg  = gp[1];
+		     trk[ntrk].clust[i].zg  = gp[2];
+		 } // end for i: detectors clust loop
+		 ntrk++; // set up for next track
+	     } // end if j>nClustMin
+	     for(i=0;iGetPositionG(gp[0],gp[1],gp[2],tof);
+         itsHit->GetDetectorID(id[0],id[1],id[2]);
+         gm->GtoL(id,gp,lp);
+	 itsHit->GetMomentumG(p[0],p[1],p[2]);
+         if(!(id[0]==ly && id[1]==ld && id[2]==dt)){//if Not the same detector
+	     j++; // incriment detector counter j.
+	     ly = id[0];
+	     ld = id[1];
+	     dt = id[2];
+	 } // end if id==idold
+	 ht[j].lay = id[0];
+	 ht[j].lad = id[1];
+	 ht[j].det = id[2];
+	 ht[j].xl += lp[0];
+	 ht[j].yl += lp[1];
+	 ht[j].zl += lp[2];
+	 ht[j].xg  = gp[0];
+	 ht[j].yg  = gp[1];
+	 ht[j].zg  = gp[2];
+	 px[j]    += p[0];
+	 py[j]    += p[1];
+	 pz[j]    += p[2];
+	 nht[j]++;
+      } // end for h
+  } // end for t: track loop
+  return;
+}
+//______________________________________________________________________
+void HitsToClustAl(ClustAl_tl *trk,Int_t &ntrk,Int_t nt,TTree *TH,AliITS *ITS,
+		   Float_t fraction){
+
+   // Local variables
+   Int_t        nClustMin = 3,Iseed;
+//   Int_t        icount=0,icountMAX=100;
+   const Int_t  jmax = 50;
+   Int_t        t,nb,nh,h,i,ly=-1,ld=-1,dt=-1,tt=-1,j=0;
+   ClustAl_sl   ht[jmax];
+   Int_t        id[3],ie[3],nht[jmax],track;
+   Float_t      gp[3],lp[3],tof;
+   Float_t      ns;
+   TClonesArray *ITShits = ITS->Hits(),*Prt = gAlice->Particles();
+   AliITShit    *itsHit;
+   TParticle    *prt;
+   // initilize and creat AliITSgeom data
+   AliITSgeom   *gm  = ITS->GetITSgeom();
+
+   for(i=0;iSetSeed(Iseed);
+   printf("gRandom->Rndm(1)=%f\n",gRandom->Rndm(1));
+   for(t=0;tRndm(1)) continue; // skip some tracks
+      gAlice->ResetHits();
+      nb = TH->GetEvent(t);
+      nh = ITShits->GetEntriesFast();
+      for(h=0;hUncheckedAt(h);
+	 track  = itsHit->fTrack;
+         prt= (TParticle *)Prt->UncheckedAt(track);
+         if(prt->P()nClustMin)if(tticountMAX) return;
+//		 icount++;
+                 // if there are enought points save data
+		 prt              = (TParticle *)Prt->UncheckedAt(tt);
+		 trk[ntrk].track  = tt;
+		 trk[ntrk].nclust = j+1;
+		 ns               = 1./(Float_t (nht[0]));
+		 trk[ntrk].px     = prt->Px();
+		 trk[ntrk].py     = prt->Py();
+		 trk[ntrk].pz     = prt->Pz();
+		 trk[ntrk].pt     = prt->Pt();
+		 trk[ntrk].p      = prt->P();
+		 trk[ntrk].clust  = new ClustAl_sl[j+1];
+		 for(i=0;i<=j;i++){ // loop over all detector hit.
+		     ns                     = 1./(Float_t(nht[i]));
+		     trk[ntrk].clust[i].lay = ie[0] = ht[i].lay;
+		     trk[ntrk].clust[i].lad = ie[1] = ht[i].lad;
+		     trk[ntrk].clust[i].det = ie[2] = ht[i].det;
+		     lp[0]                  = ht[i].xl*ns;
+		     lp[1]                  = ht[i].yl*ns;
+		     lp[2]                  = ht[i].zl*ns;
+		     // set in detector resolution on local coordiante system
+		     // z->zl rphi->xl yl-> thickness leave it alone
+		     lp[0] = lp[0]/resx[ie[0]-1];
+		     lp[0] = (Float_t)((Int_t)lp[0]);
+		     lp[0] = lp[0]*resx[ie[0]-1] + 0.5*resx[ie[0]-1];
+		     lp[2] = lp[2]/resz[ie[0]-1];
+		     lp[2] = (Float_t)((Int_t)lp[2]);
+		     lp[2] = lp[2]*resz[ie[0]-1] + 0.5*resz[ie[0]-1];
+		     //
+		     trk[ntrk].clust[i].xl  = lp[0];
+		     trk[ntrk].clust[i].yl  = lp[1];
+		     trk[ntrk].clust[i].zl  = lp[2];
+		 } // end for i: detectors clust loop
+		 ntrk++; // set up for next track
+	     } // end if j>nClustMin
+	     for(i=0;iGetPositionG(gp[0],gp[1],gp[2],tof);
+         itsHit->GetDetectorID(id[0],id[1],id[2]);
+         gm->GtoL(id,gp,lp);
+         if(!(id[0]==ly && id[1]==ld && id[2]==dt)){//if Not the same detector
+	     j++; // incriment detector counter j.
+	     ly = id[0];
+	     ld = id[1];
+	     dt = id[2];
+	 } // end if id==idold
+	 ht[j].lay = id[0];
+	 ht[j].lad = id[1];
+	 ht[j].det = id[2];
+	 ht[j].xl += lp[0];
+	 ht[j].yl += lp[1];
+	 ht[j].zl += lp[2];
+	 nht[j]++;
+      } // end for h
+  } // end for t: track loop
+  return;
+}
+//______________________________________________________________________
+void SetDetectorResolusion(Int_t l,Float_t *xl){
+    //set in detector resolution on local coordiante system
+    // z->zl rphi->xl yl-> thickness leave it alone
+    // changed from res to cell for detector simulations.
+
+    l--;
+    xl[0] = xl[0]/cellx[l];
+    xl[0] = (Float_t)((Int_t)xl[0]);
+    xl[0] = xl[0]*cellx[l] + 0.5*cellx[l];
+    xl[2] = xl[2]/cellz[l];
+    xl[2] = (Float_t)((Int_t)xl[2]);
+    xl[2] = xl[2]*cellz[l] + 0.5*cellz[l];
+    xl[1] = 0.0;
+}
+//______________________________________________________________________
+void FillAliITSAlignmentTrack(AliITSAlignmentTrack *trk,Int_t &ntrk,Int_t nt,
+			      TTree *TH,AliITS *ITS,Float_t fraction){
+    const Int_t iMAX=20,jMAX=50,nClustMin=3;
+    Int_t   ist[iMAX],imax;
+    Int_t   t,i,h,j,nh;
+    Int_t   lay,lad,det,index,track,Iseed;
+    Int_t   indexl[jMAX];
+    Float_t tof,xl[3],exl[3][3];
+    AliITSstatistics *sxl[jMAX],*szl[jMAX];
+    TParticle    *prt;
+    AliITShit    *itshit;
+    TClonesArray *ITShits = ITS->Hits();
+    AliITSgeom   *gm = ITS->GetITSgeom();
+    TClonesArray *Prt = gAlice->Particles();
+
+    printf("Entered FillAliITSAlignmentTrack\n");
+    for(i=0;iSetSeed(Iseed);
+    printf("Entering track loop. Iseed=%d\n",Iseed);
+    for(t=0;t=gRandom->Rndm(1)){
+//	gAlice->ResetHits();
+	TH->GetEvent(t);
+	nh = ITShits->GetEntriesFast();
+	i = 0;
+	ist[0] = 0;
+	printf("Entering hit loop for track=%d\n",t);
+	for(h=1;hUncheckedAt(ist[i]))->GetTrack() !=
+	       ((AliITShit *)ITShits->UncheckedAt(h))->GetTrack()) ist[++i]=h;
+	ist[++i]=nh;
+	imax = i+1;
+	printf("entering loop i nh=%d imax=%d\n",nh,imax);
+	for(i=1;iUncheckedAt(ist[i-1]);
+	    track  = itshit->GetTrack();
+	    prt    = (TParticle *)Prt->UncheckedAt(track);
+	    if(prt->P()P());
+	    for(j=0;jReset();
+		szl[j]->Reset();
+	    } // end for j
+	    printf("Exiting the reset loop, ist[%d-1]=%d\n",i,ist[i-1]);
+	    j = 0;
+	    indexl[0]=((AliITShit *)ITShits->UncheckedAt(ist[i-1]))->
+		                                                GetDetector();
+	    printf("looping over this track's hits ist[%d-1]=%d to ist[%d]=%d\n",i,ist[i-1],i,ist[i]);
+	    for(h=ist[i-1];hUncheckedAt(h);
+		index = itshit->GetDetector();
+		if(indexl[j]!=index) j++;
+		indexl[j] = index;
+		itshit->GetPositionL(xl[0],xl[1],xl[2],tof);
+		sxl[j]->AddValue((Double_t) xl[0],1.0);
+		szl[j]->AddValue((Double_t) xl[2],1.0);
+	    } // end for h
+	    if(jGetMean();
+		xl[1] = 0.0;
+		xl[2] = szl[h]->GetMean();
+		gm->GetModuleId(indexl[h],lay,lad,det);
+		printf("setting detector resolusion for index[%d]=%d (%d,%d,%d)\n",h,indexl[h],lay,lad,det);
+		SetDetectorResolusion(lay,xl);
+		printf("Detector resolusion set\n");
+		exl[0][0] = 1./(resx[lay-1]*resx[lay-1]);
+		exl[1][1] = 12./(celly[lay-1]*celly[lay-1]);
+		exl[2][2] = 1./(resz[lay-1]*resz[lay-1]);
+		printf("Adding point to trk[%d] indexl[%d]=%d\n",ntrk,h,indexl[h]);
+		trk[ntrk].AddPointLastL(indexl[h],(Float_t *)xl,
+					                     (Float_t **)exl);
+	    } // end for h
+	    ntrk++; // set up for next track
+	} // end for i
+    } // end for t // end if(fraction>=gRandom->Rndm(1))
+    for(i=0;iLtoG(id,lx,gx);
+	trk[i].clust[j].xg = gx[0];
+	trk[i].clust[j].yg = gx[1];
+	trk[i].clust[j].zg = gx[2];
+    } // end for i,j
+    return;
+}
+//______________________________________________________________________
+void PlotGeomChanges(AliITSgeom *gt,AliITSgeom *gc,TFile *Hfile,Float_t *Rdta){
+    Int_t    ly,ld,dt;
+    Float_t  x,y,z;
+    Double_t xd,yd,zd;
+    Double_t rt,rc,phit,phic,zt,zc;
+    Float_t  A0,B0,C0,A1,B1,C1;
+    Double_t dr,drphi,dz,dphi;
+    Double_t drmi,drma,drphimi,drphima,dzmi,dzma;
+
+    AliITSstatistics *R    = new AliITSstatistics(2);
+    AliITSstatistics *RPhi = new AliITSstatistics(2);
+    AliITSstatistics *Z    = new AliITSstatistics(2);
+    AliITSstatistics *A    = new AliITSstatistics(2);
+    AliITSstatistics *B    = new AliITSstatistics(2);
+    AliITSstatistics *C    = new AliITSstatistics(2);
+    TH1F *Gr  = new TH1F("Gr","Radial Displacement (cm)",500,-1.0,1.0);
+    drmi = -1.0;
+    drma = +1.0;
+    Gr->Sumw2();
+    Gr->SetXTitle("Displacement (cm)");
+    TH1F *Grphi  = new TH1F("Grphi","RPhi Displacement (cm)",500,-1.0,1.0);
+    drphimi = -1.0;
+    drphima = +1.0;
+    Grphi->Sumw2();
+    Grphi->SetXTitle("Displacement (cm)");
+    TH1F *Gz  = new TH1F("Gz","Z Displacement (cm)",500,-1.0,1.0);
+    dzmi = -1.0;
+    dzma = +1.0;
+    Gz->Sumw2();
+    Gz->SetXTitle("Displacement (cm)");
+
+    Float_t weight=1.0;
+    for(ly=1;ly<=gt->GetNlayers();ly++)for(ld=1;ld<=gt->GetNladders(ly);ld++)
+    for(dt=1;dt<=gt->GetNdetectors(ly);dt++){
+	gt->GetTrans(ly,ld,dt,x,y,z);xd=x;yd=y;zd=z;
+	gt->GetAngles(ly,ld,dt,A0,B0,C0);
+	rt    = TMath::Hypot(yd,xd);
+	phit  = TMath::ATan2(yd,xd);
+	if(phit<0.0) phit += 2.0*TMath::Pi();
+	zt    = zd;
+	gc->GetTrans(ly,ld,dt,x,y,z);xd=x;yd=y;zd=z;
+	gc->GetAngles(ly,ld,dt,A1,B1,C1);
+	rc    = TMath::Hypot(yd,xd);
+	phic  = TMath::ATan2(yd,xd);
+	if(phic<0.0) phic += 2.0*TMath::Pi();
+	zc    = zd;
+	dr    = rt-rc;
+	dphi  = phit - phic;
+	if(dphi>2.0*TMath::Pi()) dphi -= 2.0*TMath::Pi();
+	drphi = 0.5*(rt + rc)*dphi; // change in phi as measured in rphi
+	dz    = zt - zc;
+	Gr->Fill(dr,1.0);
+	Grphi->Fill(drphi,1.0);
+	Gz->Fill(dz,1.0);
+	if(dr>=drmi&&drAddValue(dr,1.0);
+	if(drphi>=drphimi&&drphiAddValue(drphi,1.0);
+	if(dz>=dzmi&&dzAddValue(dz,1.0);
+	A->AddValue(A0-A1,weight);
+	B->AddValue(B0-B1,weight);
+	C->AddValue(C0-C1,weight);
+    } // end for ly,ld,dt
+    Hfile->Write();
+    Rdta[0] = R->GetRMS();
+    Rdta[1] = RPhi->GetRMS();
+    Rdta[2] = Z->GetRMS();
+    Rdta[3] = A->GetRMS();
+    Rdta[4] = B->GetRMS();
+    Rdta[5] = C->GetRMS();
+    printf("PlotGeomChanges: RMS(r) = %f RMS(rphi) = %f RMS(z) = %f\n",
+	   R->GetRMS(),RPhi->GetRMS(),Z->GetRMS());
+    delete Gr;
+    delete Grphi;
+    delete Gz;
+    delete R;
+    delete RPhi;
+    delete Z;
+    delete A;
+    delete B;
+    delete C;
+    return;
+}
+//______________________________________________________________________
+Int_t FitTrackToLine(ClustAl_tl &trk){
+   // Local Variables
+   Int_t   i,l,j=0;
+   Double_t x,y,z,wx,wy,dx,dy;
+   Double_t a,b,c,d;
+   Double_t xb,sxb,zxb;
+   Double_t yb,syb,zyb;
+   Double_t xzb,yzb,z2xb,z2yb;
+   Double_t sum,phi=0.0,b0,d0;
+
+   trk.qual = -1.0;
+   if(trk.nclust<3) return -1;
+
+   b  = (trk.clust[0].xg-trk.clust[trk.nclust].xg)/
+        (trk.clust[0].zg-trk.clust[trk.nclust].zg);
+   d  = (trk.clust[0].yg-trk.clust[trk.nclust].yg)/
+        (trk.clust[0].zg-trk.clust[trk.nclust].zg);
+   do{
+     b0 = b;
+     d0 = d;
+     xb  = 0.0; sxb = 0.0; zxb  = 0.0;
+     yb  = 0.0; syb = 0.0; zyb  = 0.0;
+     xzb = 0.0; yzb = 0.0; z2xb = 0.0; z2yb = 0.0;
+     for(i=0;i100) return(0);
+     } // end if dx!=0.0
+     dy = zyb*zyb - z2yb*syb;
+     if(dy!=0.0){
+	 c  = zyb*yzb - yb*z2yb;
+	 c  = c/dy;
+	 d  = yb*zyb  - syb*yzb;
+	 d  = d/dy;
+     }else{
+	  printf("FitTrackToLine: Error dy=0 track=%d zyb=%f z2yb=%f syb=%f\n",
+		 trk.track,zyb,z2yb,syb);
+	  c = 0.0;
+	  d = 1.E10;
+	  j++;
+	  if(j>100) return(0);
+     } // end if dy!=0.0
+   } while(fabs(b0-b)<1.E-5 && fabs(d0-d)<1.E-5);
+   trk.a = a;
+   trk.b = b;
+   trk.c = c;
+   trk.d = d;
+   sum   = 0.0;
+   for(i=0;i2) trk.qual /= Double_t (trk.nclust-2);
+   // per degree of freedom 2 in xz 2 in yz.
+   return 0;
+}
+//______________________________________________________________________
+void LtoLline(const Int_t *id1,const Int_t *id2,
+	      Double_t a1,Double_t b1,Double_t c1,Double_t d1,
+	      Double_t &a2,Double_t &b2,Double_t &c2,Double_t &d2,
+	      AliITSgeom *gm){
+    Double_t x11[3],x12[3],x21[3],x22[3],h;
+
+    x11[0] = a1;
+    x11[1] = 0.0;
+    x11[2] = c1;
+    x12[0] = a1+b1;
+    x12[1] = 1.0;
+    x12[2] = c1+d1;
+    gm->LtoL(id1,id2,x11,x21);
+    gm->LtoL(id1,id2,x12,x22);
+    h = x21[1] - x22[1];
+    if(h!=0.0){
+	b2 = (x21[0] - x22[0])/h;
+	d2 = (x21[2] - x22[2])/h;
+	a2 = x21[0] - b2*x21[1];
+	c2 = x21[2] - d2*x21[1];
+    }else{
+	printf("LtoLline: error line in plane of detector\n");
+    } // end if h!=0
+    return;
+}
+//______________________________________________________________________
+Int_t FitTrackToLineL(ClustAl_tl &trk,AliITSgeom *gm){
+   // Local Variables
+   Int_t   i,id0[3],id[3];
+   Double_t wx/*,wy*/,wz;
+   Double_t a,b,c,d;
+   Double_t xg[3],xl[3],x2g[3],x2l[3];
+   AliITSstatistics2 *Fx  = new AliITSstatistics2(2);
+   AliITSstatistics2 *Fz  = new AliITSstatistics2(2);
+
+   trk.qual = -1.0;
+   if(trk.nclust<3) return -1;
+
+   Int_t Npts = trk.nclust;
+   id0[0] = trk.clust[0].lay;
+   id0[1] = trk.clust[0].lad;
+   id0[2] = trk.clust[0].det;
+   for(i=0;iGtoL(id0,xg,xl);
+       wx = 1.0/(resx[id[0]-1]*resx[id[0]-1]);
+       wz = 1.0/(resz[id[0]-1]*resz[id[0]-1]);
+       Fx->AddValue(xl[0],xl[1],wx);
+       Fz->AddValue(xl[2],xl[1],wz);
+   } // end for i
+   trk.qual  = Fx->FitToLine(a,b);
+   trk.qual += Fz->FitToLine(c,d);
+   trk.a0 = a;
+   trk.b0 = b;
+   trk.c0 = c;
+   trk.d0 = d;
+   xl[0]  = a;
+   xl[1]  = 0.0;
+   xl[2]  = c;
+   x2l[0] = a+b;
+   x2l[1] = 1.0;
+   x2l[2] = c+d;
+   gm->LtoG(id0,xl,xg);
+   gm->LtoG(id0,x2l,x2g);
+   c = xg[2] - x2g[2];
+   if(c!=0.0){
+       b = (xg[0] - x2g[0])/c;
+       d = (xg[1] - x2g[1])/c;
+       a = xg[0] - b*xg[2];
+       c = xg[1] - d*xg[2];
+       trk.a = a;
+       trk.b = b;
+       trk.c = c;
+       trk.d = d;
+   }else{
+       return -1;
+   }// end if c!=0.0
+   return 0;
+}
+//______________________________________________________________________
+Int_t FindCircleCenter(Double_t &x0,Double_t &y0,Double_t x1,Double_t y1,
+		       Double_t  x2,Double_t  y2,Double_t x3,Double_t y3){
+////////////////////////////////////////////////////////////////////////
+//     This was derived as folows. Given three non-linear points find
+// the circle that is therefor defined by those three non-linar points.
+// Assume that the circle is centers at x0,y0 and has a radous R. Then
+// (1) R^2 = (x1-x0)^2 + (y1-y0)^2
+// (2) R^2 = (x2-x0)^2 + (y2-y0)^2
+// (3) R^2 = (x3-x0)^2 + (y3-y0)^2.
+// Now consider the two equations derived from the above
+// (1) - (2) = x1^2 - x2^2 -2x0(x1-x2) + y1^2 - y2Y2 -2Y0(y1-y2) = 0
+// (1) - (3) = x1^2 - x3^2 -2x0(x1-x3) + y1^2 - y3Y2 -2Y0(y1-y3) = 0
+// solving these two equations for x0 and y0 gives
+// x0 = +{(y1-y2)*(y1-y3)*(y1-y3)+x1*x1*(y1-y3)+x2*x2*(y3-y1)+x3*x3*(y1-y2)}/2d
+// y0 = -{(x1-x2)*(x1-x3)*(x1-x3)+y1*y1*(x1-x3)+y2*y2*(x3-x1)+y3*y3*(x1-x2)}/2d
+// with d = (x1-x2)*(y1-y3) - (x1-x3)*(y1-y2)
+////////////////////////////////////////////////////////////////////////
+    Double_t d;
+
+    d = (x1-x2)*(y1-y3) - (x1-x3)*(y1-y2);
+    if(d==0.0) return 0;  // fits to a line!
+
+    x0 = (y1-y2)*(y1-y3)*(y1-y3)+x1*x1*(y1-y3)+x2*x2*(y3-y1)+x3*x3*(y1-y2);
+    y0 = (x1-x2)*(x1-x3)*(x1-x3)+y1*y1*(x1-x3)+y2*y2*(x3-x1)+y3*y3*(x1-x2);
+    x0 = +0.5*x0/d;
+    y0 = -0.5*y0/d;
+
+    return 1;
+}
+//______________________________________________________________________
+void FitAllTracks(ClustAl_tl *trk,Int_t ntrk,Float_t *v0,AliITSgeom *gm,
+		  const char *sfile,TFile *Hfile,Float_t *Fdta,Int_t *Ndta){
+   // Local Variables
+   Int_t    i,j,k,id0[3],id[3];
+   Double_t xm,ym,zm,dt,ad/*,rh,rp,rphih,rphip*/;
+   Double_t tp,tx,rx,rz;
+   Double_t a,b,c,d,qual;
+   Double_t xl[3],xg[3];
+   Double_t trkqualMAX = 50.0;
+   Bool_t   printit = kFALSE;
+   char     filename[80],hid[10];
+   Int_t    Nqualmax = 10,NqualgtMAX=0;
+   Int_t    Nqualless[10];
+// Distrobution statisitics
+   AliITSstatistics *Sad    = new AliITSstatistics(4);
+   AliITSstatistics *SrxzL  = new AliITSstatistics(4);
+   AliITSstatistics *SrxL[6];
+   AliITSstatistics *SrzL[6];
+   for(i=0;i<6;i++) {
+       SrxL[i] = new AliITSstatistics(4);
+       SrzL[i] = new AliITSstatistics(4);
+   } // end for i
+
+   for(i=0;iSumw2();
+   Ttqp->SetXTitle("Chi^2/degree freedom");
+   Ttqp->SetYTitle("Momentum GeV/c");
+   TH2F *Tdttq = new TH2F("Tdttq",
+			  "Distance from true vertex vs. track quality",
+			  500,0.0,0.10,100,0.0,50.0);
+   Tdttq->Sumw2();
+   Tdttq->SetXTitle("Distanct to true vertex (cm)");
+   Tdttq->SetYTitle("Chi^2/degree freedom");
+   TH2F *Tadtq = new TH2F("Tadtq",
+                     "atan(sqrt(b*b+d*d))-atan(pt/|pz|) vs. track quality",
+			  500,-0.03,0.03,500,0.0,50.0);
+   Tadtq->Sumw2();
+   Tadtq->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   Tadtq->SetYTitle("Chi^2/degree freedom");
+   TH2F *Taddt = new TH2F("Taddt",
+         "atan(sqrt(b*b+d*d))-atan(pt/|pz|) vs. Distance from true vertex",
+			  500,-0.03,0.03,200,0.0,0.10);
+   Taddt->Sumw2();
+   Taddt->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   Taddt->SetYTitle("distance to true vertex (cm)");
+   TH2F *Tadp = new TH2F("Tadp",
+         "atan(sqrt(b*b+d*d))-atan(pt/|pz|) vs. momentum",
+			  500,-0.03,0.03,200,0.0,10.0);
+   Tadp->Sumw2();
+   Tadp->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   Tadp->SetYTitle("Momentum (GeV/c)");
+
+   TH2F *TrxrzL[7];
+//   TH2F *TrrprzG[7];
+   for(i=0;i<7;i++){
+       sprintf(filename,"Layer %1.1d: xi-x(i) vs. zi-z(i) local",i+1);
+       if(i==6) sprintf(filename,"Sum of all layers: xi-x(i) "
+			"vs. zi-z(i) local");
+       sprintf(hid,"TrxrzL%1.1d",i+1);
+       TrxrzL[i] = new TH2F(hid,filename,500,-1.0,1.0,500,-1.0,1.0);
+       TrxrzL[i]->Sumw2();
+       TrxrzL[i]->SetXTitle("xi-x(i) (cm) local");
+       TrxrzL[i]->SetYTitle("zi-z(i) (cm) local");
+//
+//       sprintf(filename,"Layer %1.1d: rPhii-rPhi(i) vs. zi-z(i) local",i+1);
+//       if(i==6) sprintf(filename,"Sum of all layers: rPhii-rPhi(i) "
+//			"vs. zi-z(i) local");
+//       sprintf(hid,"TrrprzG%1.1d",i+1);
+//       TrrprzG[i] = new TH2F(hid,filename,500,-1.0,1.0,500,-1.0,1.0);
+//       TrrprzG[i]->Sumw2();
+//       TrrprzG[i]->SetXTitle("rPhii-rPhi(i) (cm) local");
+//       TrrprzG[i]->SetYTitle("zi-z(i) (cm) local");
+   } // end for i
+
+   TH1D *Tptqp[10];
+   TH1D *Ttqall = new TH1D("Ttqall","Track quality for all tracks fit",
+			   500,0.0,1000.0);
+   Ttqall->Sumw2();
+   Ttqall->SetXTitle("Track quality: Chi squared per degree freedom");
+
+// Fit each track and fill histograms and the like.
+
+   for(i=0;iFill(qual,1.0);
+      for(j=0;jtrkqualMAX) {
+//	  NqualgtMAX++;
+//	  continue;
+//      } // end if iqual>trkqualMAX=50.0
+      a = trk[i].a;
+      b = trk[i].b;
+      c = trk[i].c;
+      d = trk[i].d;
+      zm  = b*(v0[0]-a) + d*(v0[1]-c);
+      dt  = (b*b + d*d);
+      if(dt!=0.0) zm /= dt;
+      else{
+	  printf("FitAllTracks: trk[%d].b=%f trk[%d].d=%f\n",i,b,i,d);
+	  zm=0.0;
+      }// end if else dt!=0.0
+      xm  = a + b*zm;
+      ym  = c + d*zm;
+      dt   = sqrt((xm-v0[0])*(xm-v0[0]) + (ym-v0[1])*(ym-v0[1]) +
+		 (zm-v0[2])*(zm-v0[2]));
+      tx  = atan(sqrt(b*b + d*d));
+      tp  = atan2(trk[i].pt,fabs(trk[i].pz));
+      ad  = tx-tp;
+      // Fill histograms and statistics
+      Tadtq->Fill(ad,qual,1.0);
+      Sad->AddValue(ad,1.0);
+      Taddt->Fill(ad,dt,1.0);
+      Tadp->Fill(ad,trk[i].p,1.0);
+      Tdttq->Fill(dt,qual,1.0);
+      Ttqp->Fill(qual,trk[i].p,1.0);
+      //
+      id0[0] = trk[i].clust[0].lay;
+      id0[1] = trk[i].clust[0].lad;
+      id0[2] = trk[i].clust[0].det;
+      xg[0] = trk[i].clust[0].xg;
+      xg[1] = trk[i].clust[0].yg;
+      xg[2] = trk[i].clust[0].zg;
+      gm->GtoL(id0,xg,xl);
+      rx = xl[0] - trk[i].a0 - trk[i].b0 * xl[1];
+      rz = xl[2] - trk[i].c0 - trk[i].d0 * xl[1];
+      SrxL[id0[0]-1]->AddValue(rx,1.0);
+      SrzL[id0[0]-1]->AddValue(rz,1.0);
+      SrxzL->AddValue(rx,1.0);
+      SrxzL->AddValue(rz,1.0);
+      TrxrzL[6]->Fill(rx,rz,1.0);
+      TrxrzL[id0[0]-1]->Fill(rx,rz,1.0);
+      for(j=1;jGtoL(id,xg,xl);
+	  rx = xl[0] - a - b * xl[1];
+	  rz = xl[2] - c - d * xl[1];
+	  SrxL[id[0]-1]->AddValue(rx,1.0);
+	  SrzL[id[0]-1]->AddValue(rz,1.0);
+	  SrxzL->AddValue(rx,1.0);
+	  SrxzL->AddValue(rz,1.0);
+	  TrxrzL[6]->Fill(rx,rz,1.0);
+	  TrxrzL[id[0]-1]->Fill(rx,rz,1.0);
+      } // end for j
+   } // end for i
+
+// Write out information
+
+   for(i=0;i<6;i++){
+       Fdta[4*i+0] = SrxL[i]->GetRMS();
+       Fdta[4*i+1] = SrxL[i]->GetErrorRMS();
+       Fdta[4*i+2] = SrzL[i]->GetRMS();
+       Fdta[4*i+3] = SrzL[i]->GetErrorRMS();
+   } // end for i
+   for(i=0;i<10;i++) Ndta[i] = Nqualless[i];
+   Ndta[10] = Sad->GetN();
+   Ndta[11] = NqualgtMAX;
+
+   printf("FitAllTracks: %d tracks cut leaving %d, with a chi squared <%f\n",
+	  NqualgtMAX,Sad->GetN(),trkqualMAX);
+   printf("The number of tracks with chi squared <1");
+   for(i=1;iGetRMS(),Sad->GetErrorRMS(),
+	  SrxzL->GetRMS(),SrxzL->GetErrorRMS());
+
+   printf("FitAllTracks: Residuals by layer x=-rphi z ");
+   for(i=0;i<6;i++) printf(":%d:%e+-%e %e+-%e ",i+1,
+			   SrxL[i]->GetRMS(),SrxL[i]->GetErrorRMS(),
+			   SrzL[i]->GetRMS(),SrzL[i]->GetErrorRMS());
+   printf("\n");
+
+// Setup and fill projections
+
+   for(i=0;i<10;i++){
+       xm = 0.5*Double_t(i);
+       ym = xm+0.5;
+       j  = Ttqp->GetYaxis()->FindBin(xm);
+       k  = Ttqp->GetYaxis()->FindBin(ym);
+       sprintf(filename,"Track Quality for %3.1fProjectionX(filename,j,k,"E");
+       Tptqp[i]->SetXTitle("Track Quality (Chi squared/df)");
+   } // end for i
+
+   TH1D *Ttq  = Ttqp->ProjectionX("Ttq",0,Ttqp->GetNbinsY()+1,"E");
+   Ttq->SetXTitle("Chi^2/degree freedom");
+   TH1D *Tp   = Ttqp->ProjectionY("Tp", 0,Ttqp->GetNbinsX()+1,"E");
+   Tp->SetXTitle("Momentum GeV/c");
+   TH1D *Tdt  = Tdttq->ProjectionX("Tdt",0,Tdttq->GetNbinsY()+1,"E");
+   Tdt->SetXTitle("Distanct to true vertex (cm)");
+   TH1D *Tad  = Tadtq->ProjectionX("Tad",0,Tadtq->GetNbinsY()+1,"E");
+   Tad->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   TH1D *TrxL[7],*TrzL[7];
+//   TH1D *TrrphiG[7],*TrzG[7];
+   for(i=0;i<7;i++){
+       sprintf(hid,"TrxL%1.1d",i+1);
+       TrxL[i] = TrxrzL[i]->ProjectionX(hid,0,TrxrzL[i]->GetNbinsY()+1,"E");
+       TrxL[i]->SetXTitle("xi-x(i) (cm)");
+       sprintf(hid,"TrzL%1.1d",i+1);
+       TrzL[i] = TrxrzL[i]->ProjectionY(hid,0,TrxrzL[i]->GetNbinsX()+1,"E");
+       TrzL[i]->SetXTitle("zi-z(i) (cm)");
+//
+//       sprintf(hid,"TrrphiG%1.1d",i+1);
+//       TrrphiG[i] = TrrprzG[i]->ProjectionX(hid,0,
+//					      TrrprzG[i]->GetNbinsY()+1,"E");
+//       TrrphiG[i]->SetXTitle("rPhii-rPhi(i) (cm)");
+//       sprintf(hid,"TrzG%1.1d",i+1);
+//       TrzG[i] = TrrprzG[i]->ProjectionY(hid,0,
+//					   TrrprzG[i]->GetNbinsX()+1,"E");
+//       TrzG[i]->SetXTitle("zGi-zG(i) (cm)");
+   } // end for i
+
+
+   Hfile->Write();
+
+   if(printit){
+       TCanvas *c0 = new TCanvas("c0","Track quality distribution",
+				 500,100,600,700);
+       Ttqall->Draw();
+       sprintf(filename,"%s_T_tqall.ps",sfile);
+       if(printit) c0->Print(filename);
+       Ttqp->Draw("COL");
+       sprintf(filename,"%s_T_tq_p.ps",sfile);
+       if(printit) c0->Print(filename);
+       Ttq->Draw();
+       sprintf(filename,"%s_T_tq.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tp->Draw();
+       sprintf(filename,"%s_T_p.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tdttq->Draw("COL");
+       sprintf(filename,"%s_T_dt_tq.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tdt->Draw();
+       sprintf(filename,"%s_T_dt.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tadtq->Draw("COL");
+       sprintf(filename,"%s_T_ad_tq.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tad->Draw();
+       sprintf(filename,"%s_T_ad.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tadp->Draw("COL");
+       sprintf(filename,"%s_T_ad_p.ps",sfile);
+       if(printit) c0->Print(filename);
+       Taddt->Draw("COL");
+       sprintf(filename,"%s_T_ad_dt.ps",sfile);
+       if(printit) c0->Print(filename);
+       for(i=0;i<7;i++){
+	   TrxrzL[i]->Draw("COL");
+	   sprintf(filename,"%s_T%1.1d_rx_rz.ps",sfile,i+1);
+	   if(printit) c0->Print(filename);
+	   TrxL[i]->Draw();
+	   sprintf(filename,"%s_T%1.1d_rx.ps",sfile,i+1);
+	   if(printit) c0->Print(filename);
+	   TrzL[i]->Draw();
+	   sprintf(filename,"%s_T%1.1d_rz.ps",sfile,i+1);
+	   if(printit) c0->Print(filename);
+       } // end for i
+       for(i=0;i<10;i++){
+	   Tptqp[i]->Draw();
+	   sprintf(filename,"%s_T_tq_p%1.1d.ps",sfile,i);
+	   if(printit) c0->Print(filename);
+       } // end for i
+   } // end if printit
+
+// Delet allocated stuff.
+   for(i=0;i<7;i++) {
+       delete TrxL[i];
+       delete TrzL[i];
+//       delete TrrphiG[i];
+//       delete TrzG[i];
+   } // end for i
+   for(i=0;i<10;i++) delete Tptqp[i];
+   delete Ttqp;
+   delete Tdttq;
+   delete Tadtq;
+   delete Taddt;
+   delete Tadp;
+   for(i=0;i<7;i++) delete TrxrzL[i];
+//   for(i=0;i<7;i++) delete TrrprzG[i];
+   delete Ttqall;
+   delete Ttq;
+   delete Tp;
+   delete Tdt;
+   delete Tad;
+//   printf("finished with track fitting\n");
+   delete Sad;
+   delete SrxzL;
+   for(i=0;i<6;i++) delete SrxL[i];
+   for(i=0;i<6;i++) delete SrzL[i];
+   return;
+}
+//______________________________________________________________________
+void FitAllTracksG(ClustAl_tl *trk,Int_t ntrk,Float_t *v0,AliITSgeom *gm,
+		  const char *sfile,TFile *Hfile){
+   // Local Variables
+   Int_t    i,j,k,lay,lad,det;
+   Double_t xm,ym,zm,dt,ad,rh,rp,rphih,rphip;
+   Double_t tp,tx,rx,rz/*,rr*/,rrphi;
+   Double_t xg[3],xl[3],xp,yp,xh,yh,a,b,c,d,x1[3],x2[3],qual;
+   Double_t trkqualMAX = 50.0;
+   Bool_t   printit = kFALSE;
+   char     filename[80],hid[10];
+   Int_t    Nqualmax = 10,NqualgtMAX=0;
+   Int_t    Nqualless[10];
+// Distrobution statisitics
+   AliITSstatistics *Sad    = new AliITSstatistics(4);
+   AliITSstatistics *SrxzL  = new AliITSstatistics(4);
+   AliITSstatistics *SrxL[6];
+   AliITSstatistics *SrzL[6];
+   for(i=0;i<6;i++) {
+       SrxL[i] = new AliITSstatistics(4);
+       SrzL[i] = new AliITSstatistics(4);
+   } // end for i
+
+   for(i=0;iSumw2();
+   Ttqp->SetXTitle("Chi^2/degree freedom");
+   Ttqp->SetYTitle("Momentum GeV/c");
+   TH2F *Tdttq = new TH2F("Tdttq",
+			  "Distance from true vertex vs. track quality",
+			  500,0.0,0.10,100,0.0,50.0);
+   Tdttq->Sumw2();
+   Tdttq->SetXTitle("Distanct to true vertex (cm)");
+   Tdttq->SetYTitle("Chi^2/degree freedom");
+   TH2F *Tadtq = new TH2F("Tadtq",
+                     "atan(sqrt(b*b+d*d))-atan(pt/|pz|) vs. track quality",
+			  500,-0.03,0.03,500,0.0,50.0);
+   Tadtq->Sumw2();
+   Tadtq->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   Tadtq->SetYTitle("Chi^2/degree freedom");
+   TH2F *Taddt = new TH2F("Taddt",
+         "atan(sqrt(b*b+d*d))-atan(pt/|pz|) vs. Distance from true vertex",
+			  500,-0.03,0.03,200,0.0,0.10);
+   Taddt->Sumw2();
+   Taddt->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   Taddt->SetYTitle("distance to true vertex (cm)");
+   TH2F *Tadp = new TH2F("Tadp",
+         "atan(sqrt(b*b+d*d))-atan(pt/|pz|) vs. momentum",
+			  500,-0.03,0.03,200,0.0,10.0);
+   Tadp->Sumw2();
+   Tadp->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   Tadp->SetYTitle("Momentum (GeV/c)");
+
+   TH2F *TrxrzL[7],*TrrprzG[7];
+   for(i=0;i<7;i++){
+       sprintf(filename,"Layer %1.1d: xi-x(i) vs. zi-z(i) local",i+1);
+       if(i==6) sprintf(filename,"Sum of all layers: xi-x(i) "
+			"vs. zi-z(i) local");
+       sprintf(hid,"TrxrzL%1.1d",i+1);
+       TrxrzL[i] = new TH2F(hid,filename,500,-1.0,1.0,500,-1.0,1.0);
+       TrxrzL[i]->Sumw2();
+       TrxrzL[i]->SetXTitle("xi-x(i) (cm) local");
+       TrxrzL[i]->SetYTitle("zi-z(i) (cm) local");
+//
+       sprintf(filename,"Layer %1.1d: rPhii-rPhi(i) vs. zi-z(i) local",i+1);
+       if(i==6) sprintf(filename,"Sum of all layers: rPhii-rPhi(i) "
+			"vs. zi-z(i) local");
+       sprintf(hid,"TrrprzG%1.1d",i+1);
+       TrrprzG[i] = new TH2F(hid,filename,500,-1.0,1.0,500,-1.0,1.0);
+       TrrprzG[i]->Sumw2();
+       TrrprzG[i]->SetXTitle("rPhii-rPhi(i) (cm) local");
+       TrrprzG[i]->SetYTitle("zi-z(i) (cm) local");
+   } // end for i
+
+   TH1D *Tptqp[10];
+   TH1D *Ttqall = new TH1D("Ttqall","Track quality for all tracks fit",
+			   500,0.0,1000.0);
+   Ttqall->Sumw2();
+   Ttqall->SetXTitle("Track quality: Chi squared per degree freedom");
+
+// Fit each track and fill histograms and the like.
+
+   for(i=0;iFill(qual,1.0);
+      for(j=0;jtrkqualMAX) {
+	  NqualgtMAX++;
+	  continue;
+      } // end if iqual>trkqualMAX=50.0
+      a = trk[i].a;
+      b = trk[i].b;
+      c = trk[i].c;
+      d = trk[i].d;
+      zm  = b*(v0[0]-a) + d*(v0[1]-c);
+      dt  = (b*b + d*d);
+      if(dt!=0.0) zm /= dt;
+      else{
+	  printf("FitAllTracks: trk[%d].b=%f trk[%d].d=%f\n",i,b,i,d);
+	  zm=0.0;
+      }// end if else dt!=0.0
+      xm  = a + b*zm;
+      ym  = c + d*zm;
+      dt   = sqrt((xm-v0[0])*(xm-v0[0]) + (ym-v0[1])*(ym-v0[1]) +
+		 (zm-v0[2])*(zm-v0[2]));
+      tx  = atan(sqrt(b*b + d*d));
+      tp  = atan2(trk[i].pt,fabs(trk[i].pz));
+      ad  = tx-tp;
+      // Fill histograms and statistics
+      Tadtq->Fill(ad,qual,1.0);
+      Sad->AddValue(ad,1.0);
+      Taddt->Fill(ad,dt,1.0);
+      Tadp->Fill(ad,trk[i].p,1.0);
+      Tdttq->Fill(dt,qual,1.0);
+      Ttqp->Fill(qual,trk[i].p,1.0);
+      for(j=0;jTMath::Pi()){
+	      if(rphihGtoL(lay,lad,det,x1,xl);
+	  x1[0] = xl[0]; x1[1] = xl[1]; x1[2] = xl[2];
+	  if(trk[i].clust[j].zg!=0.0){
+	      x2[0] = xp; x2[1] = yp; x2[2] = trk[i].clust[j].zg;
+	  }else{
+	      x2[0] = a+b; x2[1] = c+d; x2[2] = 1.0;
+	  } // end if trk[i].clst[j].zg!=0
+	  gm->GtoL(lay,lad,det,x2,xl);
+	  x2[0] = xl[0]; x2[1] = xl[1]; x2[2] = xl[2];
+	  xg[0] = trk[i].clust[j].xg;
+	  xg[1] = trk[i].clust[j].yg;
+	  xg[2] = trk[i].clust[j].zg;
+	  xl[0] = trk[i].clust[j].xl;
+	  xl[1] = trk[i].clust[j].yl;
+	  xl[2] = trk[i].clust[j].zl;
+	  if(x1[1]!=x2[1]){
+	      rx = x1[0] - x1[1]*(x1[0]-x2[0])/(x1[1]-x2[1]);
+	      rz = x1[2] - x1[1]*(x1[2]-x2[2])/(x1[1]-x2[1]);
+	  }else{
+	      continue;
+	  } // end if x1[1]!=x2[1]
+	  rx = rx - xl[0];
+	  rz = rz - xl[2];
+	  // Fill histograms and statistics
+	  TrxrzL[lay-1]->Fill(rx,rz,1.0);
+	  TrxrzL[6]->Fill(rx,rz,1.0);
+	  TrrprzG[lay-1]->Fill(rrphi,rz,1.0);
+	  TrrprzG[6]->Fill(rrphi,rz,1.0);
+	  SrxL[lay-1]->AddValue(rx,1.0);
+	  SrzL[lay-1]->AddValue(rz,1.0);
+	  SrxzL->AddValue(rx,1.0);
+	  SrxzL->AddValue(rz,1.0);
+      } // end for j
+   } // end for i
+
+// Write out information
+
+   printf("FitAllTracks: %d tracks cut leaving %d, with a chi squared >%f\n",
+	  NqualgtMAX,Sad->GetN(),trkqualMAX);
+   printf("The number of tracks with chi squared <1");
+   for(i=1;iGetRMS(),Sad->GetErrorRMS(),
+	  SrxzL->GetRMS(),SrxzL->GetErrorRMS());
+
+   printf("FitAllTracks: Residuals by layer x=-rphi z ");
+   for(i=0;i<6;i++) printf("%f+-%f %f+-%f ",
+			   SrxL[i]->GetRMS(),SrxL[i]->GetErrorRMS(),
+			   SrzL[i]->GetRMS(),SrzL[i]->GetErrorRMS());
+   printf("\n");
+
+// Setup and fill projections
+
+   for(i=0;i<10;i++){
+       xm = 0.5*Double_t(i);
+       ym = xm+0.5;
+       j  = Ttqp->GetYaxis()->FindBin(xm);
+       k  = Ttqp->GetYaxis()->FindBin(ym);
+       sprintf(filename,"Track Quality for %3.1fProjectionX(filename,j,k,"E");
+       Tptqp[i]->SetXTitle("Track Quality (Chi squared/df)");
+   } // end for i
+
+   TH1D *Ttq  = Ttqp->ProjectionX("Ttq",0,Ttqp->GetNbinsY()+1,"E");
+   Ttq->SetXTitle("Chi^2/degree freedom");
+   TH1D *Tp   = Ttqp->ProjectionY("Tp", 0,Ttqp->GetNbinsX()+1,"E");
+   Tp->SetXTitle("Momentum GeV/c");
+   TH1D *Tdt  = Tdttq->ProjectionX("Tdt",0,Tdttq->GetNbinsY()+1,"E");
+   Tdt->SetXTitle("Distanct to true vertex (cm)");
+   TH1D *Tad  = Tadtq->ProjectionX("Tad",0,Tadtq->GetNbinsY()+1,"E");
+   Tad->SetXTitle("theta fitted line - atan(pt/p) (rad)");
+   TH1D *TrxL[7],*TrzL[7],*TrrphiG[7],*TrzG[7];
+   for(i=0;i<7;i++){
+       sprintf(hid,"TrxL%1.1d",i+1);
+       TrxL[i] = TrxrzL[i]->ProjectionX(hid,0,TrxrzL[i]->GetNbinsY()+1,"E");
+       TrxL[i]->SetXTitle("xi-x(i) (cm)");
+       sprintf(hid,"TrzL%1.1d",i+1);
+       TrzL[i] = TrxrzL[i]->ProjectionY(hid,0,TrxrzL[i]->GetNbinsX()+1,"E");
+       TrzL[i]->SetXTitle("zi-z(i) (cm)");
+//
+       sprintf(hid,"TrrphiG%1.1d",i+1);
+       TrrphiG[i] = TrrprzG[i]->ProjectionX(hid,0,
+					      TrrprzG[i]->GetNbinsY()+1,"E");
+       TrrphiG[i]->SetXTitle("rPhii-rPhi(i) (cm)");
+       sprintf(hid,"TrzG%1.1d",i+1);
+       TrzG[i] = TrrprzG[i]->ProjectionY(hid,0,
+					   TrrprzG[i]->GetNbinsX()+1,"E");
+       TrzG[i]->SetXTitle("zGi-zG(i) (cm)");
+   } // end for i
+
+
+   Hfile->Write();
+
+   if(printit){
+       TCanvas *c0 = new TCanvas("c0","Track quality distribution",
+				 500,100,600,700);
+       Ttqall->Draw();
+       sprintf(filename,"%s_T_tqall.ps",sfile);
+       if(printit) c0->Print(filename);
+       Ttqp->Draw("COL");
+       sprintf(filename,"%s_T_tq_p.ps",sfile);
+       if(printit) c0->Print(filename);
+       Ttq->Draw();
+       sprintf(filename,"%s_T_tq.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tp->Draw();
+       sprintf(filename,"%s_T_p.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tdttq->Draw("COL");
+       sprintf(filename,"%s_T_dt_tq.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tdt->Draw();
+       sprintf(filename,"%s_T_dt.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tadtq->Draw("COL");
+       sprintf(filename,"%s_T_ad_tq.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tad->Draw();
+       sprintf(filename,"%s_T_ad.ps",sfile);
+       if(printit) c0->Print(filename);
+       Tadp->Draw("COL");
+       sprintf(filename,"%s_T_ad_p.ps",sfile);
+       if(printit) c0->Print(filename);
+       Taddt->Draw("COL");
+       sprintf(filename,"%s_T_ad_dt.ps",sfile);
+       if(printit) c0->Print(filename);
+       for(i=0;i<7;i++){
+	   TrxrzL[i]->Draw("COL");
+	   sprintf(filename,"%s_T%1.1d_rx_rz.ps",sfile,i+1);
+	   if(printit) c0->Print(filename);
+	   TrxL[i]->Draw();
+	   sprintf(filename,"%s_T%1.1d_rx.ps",sfile,i+1);
+	   if(printit) c0->Print(filename);
+	   TrzL[i]->Draw();
+	   sprintf(filename,"%s_T%1.1d_rz.ps",sfile,i+1);
+	   if(printit) c0->Print(filename);
+       } // end for i
+       for(i=0;i<10;i++){
+	   Tptqp[i]->Draw();
+	   sprintf(filename,"%s_T_tq_p%1.1d.ps",sfile,i);
+	   if(printit) c0->Print(filename);
+       } // end for i
+   } // end if printit
+
+// Delet allocated stuff.
+   for(i=0;i<7;i++) {
+       delete TrxL[i];
+       delete TrzL[i];
+       delete TrrphiG[i];
+       delete TrzG[i];
+   } // end for i
+   for(i=0;i<10;i++) delete Tptqp[i];
+   delete Ttqp;
+   delete Tdttq;
+   delete Tadtq;
+   delete Taddt;
+   delete Tadp;
+   for(i=0;i<7;i++) delete TrxrzL[i];
+   for(i=0;i<7;i++) delete TrrprzG[i];
+   delete Ttqall;
+   delete Ttq;
+   delete Tp;
+   delete Tdt;
+   delete Tad;
+//   printf("finished with track fitting\n");
+   delete Sad;
+   delete SrxzL;
+   for(i=0;i<6;i++) delete SrxL[i];
+   for(i=0;i<6;i++) delete SrzL[i];
+   return;
+}
+//______________________________________________________________________
+void FindVertex2(ClustAl_tl &trk1,ClustAl_tl &trk2,Double_t *vt,Double_t &d){
+   // Local Variables
+   Double_t x1,y1,x2,y2;
+   Double_t z1,z2;
+   Double_t a1,b1,c1,d1;
+   Double_t a2,b2,c2,d2;
+   Double_t da,db,dc,dd,dbd;
+   Double_t den,num1,num2;
+
+   a1 = trk1.a; b1 = trk1.b; c1 = trk1.c; d1 = trk1.c;
+   a2 = trk2.a; b2 = trk2.b; c2 = trk2.c; d2 = trk2.c;
+
+   // Find z1 and z2 of points of closest approch.
+   da = a1-a2;
+   db = b1-b2;
+   dc = c1-c2;
+   dd = d1-d2;
+   dbd = b1*d2-d1*b2;
+   den = -db*db - dd*dd - dbd*dbd;
+   num1 = da*(db+d1*dbd) + dc*(dd-b1*dbd);
+   num2 = da*(db+d2*dbd) + dc*(dd-b2*dbd);
+   if(den!=0.0){
+       z1 = num1/den;
+       z2 = num2/den;
+   }else{ // parallel lines
+       z1 = 0.0;
+       z2 = 0.0;
+   } // end if den!-0.0
+
+   // find coordinate of closest approch and distance between.
+   x1    = a1+b1*z1; y1 = c1+d1*z1;
+   x2    = a2+b2*z2; y2 = c2*d2*z2;
+   vt[0] = 0.5*(x1+x2);
+   vt[1] = 0.5*(y1+y2);
+   vt[2] = 0.5*(z1+z2);
+   d     = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
+
+   return;
+}
+//______________________________________________________________________
+void FitVertexAll(ClustAl_tl *trk,Int_t ntrk,const char *sfile,TFile *Hfile){
+   // Local Variables
+   Int_t    i,j,k;
+   Double_t d,vz,r,q;
+   Double_t vt[3];
+   Bool_t   printit = kFALSE;
+   char     filename[80],hid[10];
+   Double_t trkqualMAX = 50.0;
+   const Int_t    IntQualMax=10;
+   Int_t    QualInt[IntQualMax];
+   AliITSstatistics *Svz   = new AliITSstatistics(4);
+   AliITSstatistics *Svx   = new AliITSstatistics(4);
+   AliITSstatistics *Svy   = new AliITSstatistics(4);
+   //   Double_t vzmi=-0.20,vzma=0.20,vxmi=-1.0,vxma=1.0,vymi=-1.0,vyma=1.0;
+
+   for(i=0;iSumw2();
+       Vvzbtq[i]->SetXTitle("Z of vertex (cm)");
+   } // end for i
+
+   TH2F *Vvztq  = new TH2F("Vvztq","Z of vertex of pairs vs. track quality cut",
+			   500,-0.20,0.20,200,0.0,20.0);
+   Vvztq->Sumw2();
+   Vvztq->SetXTitle("Z of vertex (cm)");
+   Vvztq->SetYTitle("Chi^2/degree freedom");
+   TH2F *Vvzvr  = new TH2F("Vvzvr","Z vs. R of vertex of pairs",
+			                       200,-0.20,0.20,400,0.0,5.0);
+   Vvzvr->Sumw2();
+   Vvzvr->SetXTitle("Z of vertex (cm)");
+   Vvzvr->SetYTitle("R of vertex (cm)");
+   TH2F *Vdtq   = new TH2F("Vdtq","Distance between lines vs. track quality cut",
+			   500,0.0,0.2,200,0.0,50.0);
+   Vdtq->Sumw2();
+   Vdtq->SetXTitle("minimum distance between lines (cm)");
+   Vdtq->SetYTitle("Chi^2/degree freedom");
+   TH2F *Vvzd   = new TH2F("Vvzd","Z vertex vs. Dist between lines",
+                                               500,-5.0,5.0,200,0.0,5.0);
+   Vvzd->Sumw2();
+   Vvzd->SetXTitle("Z of vertex (cm)");
+   Vvzd->SetYTitle("minimmum distance between lined (cm)");
+   TH2F *Vvxvy  = new TH2F("Vvxvy","X vertex vs. Y vertex",
+                                               200,-10.0,10.0,200,-10.0,10.0);
+   Vvxvy->Sumw2();
+   Vvxvy->SetXTitle("X of vertex (cm)");
+   Vvxvy->SetYTitle("Y of vertex (cm)");
+   TH2F *Vvxvz  = new TH2F("Vvxvz","X vertex vs. Z vertex",
+                                               200,-10.0,10.0,200,-10.0,10.0);
+   Vvxvz->Sumw2();
+   Vvxvz->SetXTitle("X of vertex (cm)");
+   Vvxvz->SetYTitle("Z of vertex (cm)");
+   TH2F *Vvyvz  = new TH2F("Vvyvz","Y vertex vs. Z vertex",
+                                               200,-10.0,10.0,200,-10.0,10.0);
+   Vvyvz->Sumw2();
+   Vvyvz->SetXTitle("Y of vertex (cm)");
+   Vvyvz->SetYTitle("Z of vertex (cm)");
+
+   for(i=0;itrkqualMAX||trk[i].qual<0.0) continue;
+       for(j=i+1;jtrkqualMAX||trk[i].qual<0.0) continue;
+	   FindVertex2(trk[i],trk[j],vt,d);
+	   q  = TMath::Max(trk[i].qual,trk[j].qual);
+	   r  = vt[0]*vt[0] + vt[1]*vt[1];
+	   r  = sqrt(r);
+	   vz = vt[2];
+           Vvxvy->Fill(vt[0],vt[1],1.0);
+           Vvxvz->Fill(vt[0],vt[2],1.0);
+           Vvyvz->Fill(vt[1],vt[2],1.0);
+	   Svx->AddValue(vt[0],1.0);
+	   Svy->AddValue(vt[1],1.0);
+	   Svz->AddValue(vt[2],1.0);
+	   Vvztq->Fill(vz,q,1.0);
+	   Vvzvr->Fill(vz,r,1.0);
+	   Vdtq->Fill(d,q,1.0);
+	   Vvzd->Fill(vz,d,1.0);
+	   for(k=0;kFill(vz,1.);
+       } // end for j
+   } // end for i
+
+   TH1D *Vd  = Vvzd->ProjectionY ("Vd", 0,Vvzd->GetNbinsX()+1,"E");
+   Vd->SetXTitle("minimum distance between lines (cm)");
+   TH1D *Vvr = Vvzvr->ProjectionY("Vvr",0,Vvzvr->GetNbinsX()+1,"E");
+   Vvr->SetXTitle("R of vertex (cm)");
+   TH1D *Vtq = Vdtq->ProjectionY ("Vtq",0,Vdtq->GetNbinsX()+1,"E");
+   Vtq->SetXTitle("Chi^2/degree freedom");
+//
+   TH1D *Vvx = Vvxvy->ProjectionX("Vvx",0,Vvxvy->GetNbinsY()+1,"E");
+   Vvx->SetXTitle("X of vertex (cm)");
+   TH1D *Vvy = Vvxvy->ProjectionY("Vvy",0,Vvxvy->GetNbinsX()+1,"E");
+   Vvy->SetXTitle("Y of vertex (cm)");
+   TH1D *Vvz = Vvxvz->ProjectionX ("Vvz",0,Vvxvz->GetNbinsY()+1,"E");
+   Vvz->SetXTitle("Z of vertex (cm)");
+
+   printf("FitVertexAll: N(track pairs Qual <=1");
+   for(k=1;kGetRMS(),Svx->GetErrorRMS(),
+	  Svy->GetRMS(),Svy->GetErrorRMS(),
+	  Svz->GetRMS(),Svy->GetErrorRMS());
+   Hfile->Write();
+
+   if(printit){
+       TCanvas *c1 = new TCanvas("c1","Vertex info",500,100,600,700);
+       for(k=0;kDraw();
+	   sprintf(filename,"%s_V_vz_tq%2.2d.ps",sfile,k+1);
+	   if(printit) c1->Print(filename);
+       } // end for k
+       Vvzd->Draw("COL");
+       sprintf(filename,"%s_V_vz_d.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvzvr->Draw("COL");
+       sprintf(filename,"%s_V_vz_vr.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vdtq->Draw("COL");
+       sprintf(filename,"%s_V_d_tq.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvztq->Draw("COL");
+       sprintf(filename,"%s_V_vz_tq.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvz->Draw();
+       sprintf(filename,"%s_V_vz.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vd->Draw();
+       sprintf(filename,"%s_V_d.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvr->Draw();
+       sprintf(filename,"%s_V_vr.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vtq->Draw();
+       sprintf(filename,"%s_V_tq.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvxvy->Draw("COL");
+       sprintf(filename,"%s_V_vx_vy.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvxvz->Draw("COL");
+       sprintf(filename,"%s_V_vx_vz.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvyvz->Draw("COL");
+       sprintf(filename,"%s_V_vy_vz.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvx->Draw();
+       sprintf(filename,"%s_V_vx.ps",sfile);
+       if(printit) c1->Print(filename);
+       Vvy->Draw();
+       sprintf(filename,"%s_V_vy.ps",sfile);
+       if(printit) c1->Print(filename);
+   } // end if printit
+   for(k=0;kGetEvent(evnt);
+    printf("nparticles %d\n",nparticles);
+    if (nparticles <= 0) return; /* get next event */
+
+// Get pointers to Alice detectors and Clusts containers
+    AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
+    if(!ITS) return;          /* error no ITS data exit */
+    TTree *TH   = gAlice->TreeH();
+    Int_t Ntrkp =  (Int_t) TH->GetEntries(),ntrk;
+    AliITSgeom gm2,gm3,*gm = ITS->GetITSgeom();
+    Int_t Nmods = gm->GetIndexMax();
+    Float_t   trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			  2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			  2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
+    Float_t   rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
+			 2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
+			 2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
+   Float_t     tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
+   TFile *Hfile;
+   Float_t     Rdta[6];
+   Int_t Itimes=0,i,j,badmod;
+   Double_t Chi2b;
+
+// Array (stucture) of clusts for the first and second layer
+// this should be replaced with either clusters or digits
+// when they are proporly defined.
+    AliITSAlignmentTrack *trk = new AliITSAlignmentTrack[Ntrkp];
+    TObjArray *mods = new TObjArray(Nmods);
+    AliITSAlignmentModule *mod;
+
+    printf("Ntrkp=%d\n",Ntrkp);
+
+    FillAliITSAlignmentTrack(trk,ntrk,Ntrkp,TH,ITS,fraction);
+
+    for(Int_t Isigmas=0;Isigmas<1;Isigmas++){
+//
+//      tran[0] = sigma1;
+//	tran[1] = sigma2;
+//	tran[2] = sigma3;
+	if(Itimes==0){ tran[0] = trans[Isigmas];
+	}else tran[0] = 0.0;
+	if(Itimes==1){ tran[1] = trans[Isigmas];
+	}else tran[1] = 0.0;
+	if(Itimes==2){ tran[2] = trans[Isigmas];
+	}else tran[2] = 0.0;
+	if(Itimes==3){ rot[0] = rots[Isigmas];
+	}else rot[0] = 0.0;
+	if(Itimes==4){ rot[1] = rots[Isigmas];
+	}else rot[1] = 0.0;
+	if(Itimes==5){ rot[2] = rots[Isigmas];
+	}else rot[2] = 0.0;
+	printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
+	       tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
+//
+	gm2 = *gm;
+	gm2.RandomCylindericalChange(tran,rot);
+	gm3 = gm2;
+	Hfile = new TFile("Alignment_geom_0_2.root","RECREATE",
+			  "comparison of geometry before refitting");
+        PlotGeomChanges(gm,&gm2,Hfile,Rdta);
+	Hfile -> Close();
+
+	for(i=0;iAddAt(new AliITSAlignmentModule(i,&gm3,
+                                                                  ntrk,trk),i);
+//
+	j = 0;
+	do{
+	    for(i=0;iAt(i)))->GetChi2()>Chi2b){
+		    Chi2b =((AliITSAlignmentModule *)(mods->At(i)))->GetChi2();
+		    badmod = i;
+		} // end if
+	    } // end for i
+	    mod = (AliITSAlignmentModule *)(mods->At(badmod));
+	    mod->AlignModule();
+	    gm3.SetTrans(badmod,mod->GetTranslationVector());
+	    gm3.SetByAngles(badmod,mod->GetRotationAngles());
+	}while(jClose();
+    printf("Event %d done\n",evnt);
+//
+    delete[] trk;            // now delet memory allocated above.
+}
+//______________________________________________________________________
diff --git a/ITS/AnalysisITSAlignment.h b/ITS/AnalysisITSAlignment.h
new file mode 100644
index 00000000000..aee76401b00
--- /dev/null
+++ b/ITS/AnalysisITSAlignment.h
@@ -0,0 +1,48 @@
+#ifndef ALIGNITS_H
+#define ALIGNITS_H
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+#include "AliITS.h"
+#include "TTree.h"
+#include "TClonesArray.h"
+#include "AliRun.h"
+#include "AliITSAlignmentTrack.h"
+
+// Data structure to hold averaged clusts.
+struct ClustAl_sl{
+    Int_t lay,lad,det;
+    Float_t xg,yg,zg,xl,yl,zl;
+};
+struct ClustAl_tl{
+    Int_t    track,nclust;  // track number and number of data points.
+    ClustAl_sl *clust;        // data points to fit.
+    Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
+    Float_t  px,py,pz,p,pt;
+    // x=a+b*z and y=c+d*z;
+    // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
+};
+
+void HitsTo(ClustAl_tl *trk,Int_t &ntrk,Int_t,TTree *TH,AliITS *ITS,
+	    Float_t nsigmaT1,Float_t nsigmaT2,Float_t nsigmaT3,
+	    Float_t nsigmaR1,Float_t nsigmaR2,Float_t nsigmaR3);
+void HitsToClustAl(ClustAl_tl *trk,Int_t &ntrk,Int_t nt,TTree *TH,
+		   AliITS *ITS,Float_t fraction);
+void PlotGeomChanges(AliITSgeom *gt,AliITSgeom *gc,TFile *Hfile,Float_t *Rdta);
+void FillGlobalPositions(ClustAl_tl *trk,Int_t ntrk,AliITSgeom *g);
+void FitAllTracks(ClustAl_tl *trk,Int_t ntrk,Float_t *v0,AliITSgeom *gm,
+		  const char *sfile,TFile *Hfile,Float_t *Fdta,Int_t *Ndta);
+void FitVertexAll(ClustAl_tl *trk,Int_t ntrk,const char *sfile,TFile *Hfile);
+void OnlyOneGeometry(char *filename,AliITSgeom *gm,AliITSgeom &gm2,
+		     Float_t trans[],Float_t rot[]);
+void deleteClustAl(ClustAl_tl *trk,Int_t ntrk);
+void FillAliITSAlignmentTrack(AliITSAlignmentTrack *trk,Int_t &ntrk,Int_t nt,
+			      TTree *TH,AliITS *ITS,Float_t fraction);
+void RunAlignment(Int_t evnt,Float_t fraction);
+
+#endif
diff --git a/ITS/Config.C b/ITS/Config.C
index 1b4c281cac9..8d0f636cf62 100644
--- a/ITS/Config.C
+++ b/ITS/Config.C
@@ -44,7 +44,7 @@ geant3->SetCUTS(cut,cut, cut, cut, cut, cut,  cut,  cut, cut,  cut, tofmax);
 // --- All positions are in cm, angles in degrees, and P and E in GeV
 
 
-AliGenHIJINGpara *gener = new AliGenHIJINGpara(100);
+AliGenHIJINGpara *gener = new AliGenHIJINGpara(1000);
 gener->SetMomentumRange(0,999);
 gener->SetPhiRange(0,360);
 gener->SetThetaRange(10,170);
diff --git a/ITS/ITSDigitsToClusters.C b/ITS/ITSDigitsToClusters.C
new file mode 100644
index 00000000000..6aab113048f
--- /dev/null
+++ b/ITS/ITSDigitsToClusters.C
@@ -0,0 +1,128 @@
+#include "iostream.h"
+
+void ITSDigitsToClusters (Int_t evNumber1=0,Int_t evNumber2=0) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } else {
+      delete gAlice;
+      gAlice=0;
+   }
+
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   printf("file %p\n",file);
+   if (file) file->Close(); 
+   file = new TFile("galice.root","UPDATE");
+   file->ls();
+
+   printf ("I'm after Map \n");
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+       gAlice = (AliRun*)file->Get("gAlice");
+       if (gAlice) printf("AliRun object found on file\n");
+       if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+   printf ("I'm after gAlice \n");
+   
+   AliITS *ITS  = (AliITS*) gAlice->GetModule("ITS");
+   if (!ITS) return;
+
+   AliITSgeom *geom = ITS->GetITSgeom();
+
+
+   // Set the models for cluster finding
+
+   // SPD
+
+   AliITSDetType *iDetType=ITS->DetType(0);
+   AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
+   TClonesArray *dig0  = ITS->DigitsAddress(0);
+   TClonesArray *recp0  = ITS->ClustersAddress(0);
+   AliITSClusterFinderSPD *rec0=new AliITSClusterFinderSPD(seg0,dig0,recp0);
+   ITS->SetReconstructionModel(0,rec0);
+   // test
+   printf("SPD dimensions %f %f \n",seg0->Dx(),seg0->Dz());
+   printf("SPD npixels %d %d \n",seg0->Npz(),seg0->Npx());
+
+
+   // SDD
+
+   AliITSDetType *iDetType=ITS->DetType(1);
+   AliITSgeom *geom = ITS->GetITSgeom();
+
+   AliITSsegmentationSDD *seg1=(AliITSsegmentationSDD*)iDetType->GetSegmentationModel();
+   if (!seg1) seg1 = new AliITSsegmentationSDD(geom);
+   AliITSresponseSDD *res1 = (AliITSresponseSDD*)iDetType->GetResponseModel();
+   if (!res1) res1=new AliITSresponseSDD();
+   TClonesArray *dig1  = ITS->DigitsAddress(1);
+   TClonesArray *recp1  = ITS->ClustersAddress(1);
+   AliITSClusterFinderSDD *rec1=new AliITSClusterFinderSDD(seg1,res1,dig1,recp1);
+   ITS->SetReconstructionModel(1,rec1);
+
+
+
+   // SSD
+
+   AliITSDetType *iDetType=ITS->DetType(2);
+   AliITSsegmentationSSD *seg2=(AliITSsegmentationSSD*)iDetType->GetSegmentationModel();
+   TClonesArray *dig2  = ITS->DigitsAddress(2);
+   TClonesArray *recp2  = ITS->ClustersAddress(2);
+   AliITSClusterFinderSSD *rec2=new AliITSClusterFinderSSD(seg2,dig2,recp2);
+   ITS->SetReconstructionModel(2,rec2);
+   // test
+   printf("SSD dimensions %f %f \n",seg2->Dx(),seg2->Dz());
+   printf("SSD nstrips %d %d \n",seg2->Npz(),seg2->Npx());
+
+
+
+//
+// Event Loop
+//
+
+   for (int nev=evNumber1; nev<= evNumber2; nev++) {
+       Int_t nparticles = gAlice->GetEvent(nev);
+       cout << "nev         " <TreeD();
+       Int_t nent=TD->GetEntries();
+       printf("Found %d entries in the tree (must be one per module per event!)\n",nent);
+       //Int_t nmodules=geom->GetLastSSD();
+       //Int_t last_entry=nent-(nmodules+1);
+       Int_t last_entry=1;
+       ITS->DigitsToRecPoints(nev,last_entry,"All");
+   } // event loop 
+
+   file->Close();
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ITS/ITSHitsToDigits.C b/ITS/ITSHitsToDigits.C
new file mode 100644
index 00000000000..e33973782a2
--- /dev/null
+++ b/ITS/ITSHitsToDigits.C
@@ -0,0 +1,133 @@
+#include "iostream.h"
+
+void ITSHitsToDigits (Int_t evNumber1=0,Int_t evNumber2=0,Int_t nsignal  =25, Int_t size=-1) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } 
+
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   printf("file %p\n",file);
+   if (file) file->Close(); 
+   if (!file) file = new TFile("galice.root","UPDATE");
+   file->ls();
+
+   printf ("I'm after Map \n");
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+       gAlice = (AliRun*)file->Get("gAlice");
+       if (gAlice) printf("AliRun object found on file\n");
+       if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+   printf ("I'm after gAlice \n");
+   
+   AliITS *ITS  = (AliITS*) gAlice->GetModule("ITS");
+   if (!ITS) return;
+
+
+   // Set the simulation models
+
+   AliITSgeom *geom = ITS->GetITSgeom();
+
+   // SDD
+   // SDD compression param: 2 fDecrease, 2fTmin, 2fTmax or disable, 2 fTolerance
+
+   Int_t cp[8]={0,0,0,0,0,0,0,0};
+
+   AliITSDetType *iDetType=ITS->DetType(1);
+   AliITSresponseSDD *res1 = (AliITSresponseSDD*)iDetType->GetResponseModel();
+   if (!res1) {
+         res1=new AliITSresponseSDD();
+         ITS->SetResponseModel(1,res1);
+   }
+   res1->SetZeroSupp("2D");
+   //res1->SetZeroSupp("1D");
+   res1->SetNoiseParam(0.,0.);
+   res1->SetCompressParam(cp);
+   res1->SetMinVal(4);
+
+   AliITSsegmentationSDD *seg1=(AliITSsegmentationSDD*)iDetType->GetSegmentationModel();
+   if (!seg1) {
+       seg1 = new AliITSsegmentationSDD(geom,res1);
+       ITS->SetSegmentationModel(1,seg1);
+   }
+
+   AliITSsimulationSDD *sim1=new AliITSsimulationSDD(seg1,res1);
+   ITS->SetSimulationModel(1,sim1);
+   
+   
+
+   // SPD
+
+   AliITSDetType *iDetType=ITS->DetType(0);
+   AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
+   AliITSresponseSPD *res0 = (AliITSresponseSPD*)iDetType->GetResponseModel();
+   AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
+   ITS->SetSimulationModel(0,sim0);
+   // test
+   printf("SPD dimensions %f %f \n",seg0->Dx(),seg0->Dz());
+   printf("SPD npixels %d %d \n",seg0->Npz(),seg0->Npx());
+   printf("SPD pitches %d %d \n",seg0->Dpz(0),seg0->Dpx(0));
+   // end test
+
+
+   // SSD
+
+   AliITSDetType *iDetType=ITS->DetType(2);
+   AliITSsegmentationSSD *seg2=(AliITSsegmentationSSD*)iDetType->GetSegmentationModel();
+   AliITSresponseSSD *res2 = (AliITSresponseSSD*)iDetType->GetResponseModel();
+   res2->SetSigmaSpread(3.,2.);
+   AliITSsimulationSSD *sim2=new AliITSsimulationSSD(seg2,res2);
+   ITS->SetSimulationModel(2,sim2);
+
+
+//
+// Event Loop
+//
+
+   Int_t nbgr_ev=0;
+
+   for (Int_t nev=evNumber1; nev<= evNumber2; nev++) {
+       cout << "nev         " <GetEvent(nev);
+       cout << "nparticles  " <HitsToDigits(nev,nbgr_ev,size," ","All"," ");
+       //ITS->HitsToDigits(nev,nbgr_ev,size," ","SDD"," ");
+   } // event loop 
+
+   file->Close();
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ITS/ITSHitsToFastPoints.C b/ITS/ITSHitsToFastPoints.C
new file mode 100644
index 00000000000..e491e124ee2
--- /dev/null
+++ b/ITS/ITSHitsToFastPoints.C
@@ -0,0 +1,81 @@
+#include "iostream.h"
+
+void ITSHitsToFastPoints (Int_t evNumber1=0,Int_t evNumber2=0,Int_t nsignal=25, Int_t size=-1) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   if (file) file->Close(); 
+   file = new TFile("galice.root","UPDATE");
+   file->ls();
+
+   printf ("I'm after Map \n");
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+       gAlice = (AliRun*)file->Get("gAlice");
+       if (gAlice) printf("AliRun object found on file\n");
+       if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+   printf ("I'm after gAlice \n");
+   
+   AliITS *ITS  = (AliITS*) gAlice->GetModule("ITS");
+   if (!ITS) return;
+
+   // Set the simulation model
+   AliITSsimulationFastPoints *sim = new AliITSsimulationFastPoints();
+
+   for (Int_t i=0;i<3;i++) {
+       ITS->SetSimulationModel(i,sim);
+   }
+
+//
+// Event Loop
+//
+
+   Int_t nbgr_ev=0;
+
+   for (int ev=evNumber1; ev<= evNumber2; ev++) {
+       Int_t nparticles = gAlice->GetEvent(ev);
+       cout << "event         " <HitsToFastRecPoints(ev,bgr_ev,size," ","All"," ");
+   } // event loop 
+
+   file->Close();
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ITS/ITSLinkDef.h b/ITS/ITSLinkDef.h
index 470141d824a..d6e06a98f4c 100644
--- a/ITS/ITSLinkDef.h
+++ b/ITS/ITSLinkDef.h
@@ -7,6 +7,9 @@
 #pragma link off all globals;
 #pragma link off all classes;
 #pragma link off all functions;
+//#pragma link C++ enum   Cluster_t;
+
+//#pragma link C++ global gITSdisplay;  // global used by AliITSdisplay
 
 // Standard ITS classes 
  
@@ -15,59 +18,84 @@
 #pragma link C++ class  AliITSv3-;
 #pragma link C++ class  AliITSv5-;
 #pragma link C++ class  AliITShit-;
-#pragma link C++ class  AliITSdigit;
-#pragma link C++ class  AliITSdigitSPD;
-#pragma link C++ class  AliITSdigitSDD;
-#pragma link C++ class  AliITSdigitSSD;
-#pragma link C++ class  AliITSTransientDigit;
+#pragma link C++ class  AliITSdigit+;
+#pragma link C++ class  AliITSdigitSPD+;
+#pragma link C++ class  AliITSdigitSDD+;
+#pragma link C++ class  AliITSdigitSSD+;
+#pragma link C++ class  AliITSTransientDigit+;
 #pragma link C++ class  AliITSgeom-;
-#pragma link C++ class  AliITSgeomSPD;
-#pragma link C++ class  AliITSgeomSDD;
-#pragma link C++ class  AliITSgeomSSD;
+#pragma link C++ class  AliITSgeomSPD+;
+#pragma link C++ class  AliITSgeomSDD+;
+#pragma link C++ class  AliITSgeomSSD+;
 
 #pragma link C++ class AliITSgeomSPD300-;
 #pragma link C++ class AliITSgeomSPD425-;
 
-#pragma link C++ class  AliITSmodule;
-#pragma link C++ class  AliITSRecPoint;
-#pragma link C++ class  AliITSRawCluster;
-#pragma link C++ class  AliITSRawClusterSPD;
-#pragma link C++ class  AliITSRawClusterSDD;
-#pragma link C++ class  AliITSRawClusterSSD;
-#pragma link C++ class  AliITSMap;
-#pragma link C++ class  AliITSMapA1-;
-#pragma link C++ class  AliITSMapA2-;
-#pragma link C++ class  AliITSsegmentation;
-#pragma link C++ class  AliITSsegmentationSPD;
-#pragma link C++ class  AliITSsegmentationSDD;
-#pragma link C++ class  AliITSsegmentationSSD;
-#pragma link C++ class  AliITSresponse;
-#pragma link C++ class  AliITSresponseSPD;
-#pragma link C++ class  AliITSresponseSDD;
-#pragma link C++ class  AliITSresponseSSD;
-#pragma link C++ class  AliITSsimulation;
-#pragma link C++ class  AliITSsimulationSPD;
-#pragma link C++ class  AliITSsimulationSDD-;
-#pragma link C++ class  AliITSsimulationSSD;
-#pragma link C++ class  AliITSsimulationFastPoints;
-#pragma link C++ class  AliITSClusterFinder;
-#pragma link C++ class  AliITSClusterFinderSPD;
-#pragma link C++ class  AliITSClusterFinderSDD;
-#pragma link C++ class  AliITSClusterFinderSSD;
-#pragma link C++ class  AliITSDetType;
+#pragma link C++ class  AliITSmodule+;
+#pragma link C++ class  AliITSRecPoint+;
+#pragma link C++ class  AliITSRawCluster+;
+#pragma link C++ class  AliITSRawClusterSPD+;
+#pragma link C++ class  AliITSRawClusterSDD+;
+#pragma link C++ class  AliITSRawClusterSSD+;
+#pragma link C++ class  AliITSMap+;
+#pragma link C++ class  AliITSMapA1+;
+#pragma link C++ class  AliITSMapA2+;
+#pragma link C++ class  AliITSsegmentation+;
+#pragma link C++ class  AliITSsegmentationSPD+;
+#pragma link C++ class  AliITSsegmentationSDD+;
+#pragma link C++ class  AliITSsegmentationSSD+;
+#pragma link C++ class  AliITSresponse+;
+#pragma link C++ class  AliITSresponseSPD+;
+#pragma link C++ class  AliITSresponseSDD+;
+#pragma link C++ class  AliITSresponseSSD+;
+#pragma link C++ class  AliITSsimulation+;
+#pragma link C++ class  AliITSsimulationSPD+;
+#pragma link C++ class  AliITSsimulationSDD+;
+#pragma link C++ class  AliITSsimulationSSD+;
+#pragma link C++ class  AliITSsimulationFastPoints+;
+#pragma link C++ class  AliITSsimulationFastPointsV0+;
+#pragma link C++ class  AliITSClusterFinder+;
+#pragma link C++ class  AliITSClusterFinderSPD+;
+#pragma link C++ class  AliITSClusterFinderSDD+;
+#pragma link C++ class  AliITSClusterFinderSSD+;
+#pragma link C++ class  AliITSDetType+;
+#pragma link C++ class  AliITStrack+;
 // SDD simulation
-#pragma link C++ class  AliITSRawData;
+#pragma link C++ class  AliITSRawData+;
 #pragma link C++ class  AliITSInStream-;
 #pragma link C++ class  AliITSOutStream-;
-#pragma link C++ class  AliITSHNode;
-#pragma link C++ class  AliITSHTable-;
-#pragma link C++ class  AliITSetfSDD;
+#pragma link C++ class  AliITSHNode+;
+#pragma link C++ class  AliITSHTable+;
+#pragma link C++ class  AliITSetfSDD+;
 // SSD simulation and reconstruction
-#pragma link C++ class  AliITSdictSSD;
-#pragma link C++ class  AliITSdcsSSD;
-#pragma link C++ class  AliITSclusterSSD;
-#pragma link C++ class  AliITSpackageSSD;
+#pragma link C++ class  AliITSdictSSD+;
+#pragma link C++ class  AliITSdcsSSD+;
+#pragma link C++ class  AliITSclusterSSD+;
+#pragma link C++ class  AliITSpackageSSD+;
+// New used for Alignment studdies
+#pragma link C++ class  AliITSAlignmentTrack-;
+#pragma link C++ class  AliITSAlignmentModule-;
+#pragma link C function HitsTo;
+#pragma link C function HitsToClustAl;
+#pragma link C function FillGlobalPositions;
+#pragma link C function PlotGeomChanges;
+#pragma link C function FitAllTracks;
+#pragma link C function FitVertexAll;
+#pragma link C function OnlyOneGeometry;
+#pragma link C function deleteClustAl;
 #pragma link C++ class  AliITSstatistics-;
 #pragma link C++ class  AliITSstatistics2-;
+// New used for AliITSdisplay
+//#pragma link C++ class  AliITSdisplay;
+//#pragma link C++ class  AliITSDisplay;
+//#pragma link C++ class  TInputDialog;   // MUST BE RENAMED
+//#pragma link C function OpenFileDialog;
+//#pragma link C function GetStringDialog;
+//#pragma link C function GetIntegerDialog;
+//#pragma link C function GetFloatDialog;
+// New classes used for Tracking
+
+// This class will always be for ITS only
+#pragma link C++ class  AliITSvtest-;
 
 #endif
diff --git a/ITS/ITSdigitsTest.C b/ITS/ITSdigitsTest.C
index 4072b686abb..cff5df145e8 100644
--- a/ITS/ITSdigitsTest.C
+++ b/ITS/ITSdigitsTest.C
@@ -54,7 +54,7 @@ void ITSdigitsTest (Int_t evNumber1=0,Int_t evNumber2=0)
    AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
    TClonesArray *Particles = gAlice->Particles();
    TTree *TD = gAlice->TreeD();
-   TD->Print();
+   //TD->Print();
    Int_t nent=TD->GetEntries();
    printf("Found %d entries in the tree (must be one per module per event!)\n",nent);
    if (ITS) {
@@ -72,7 +72,7 @@ void ITSdigitsTest (Int_t evNumber1=0,Int_t evNumber2=0)
 	    //Int_t nmodules=2269;
 	    //for (Int_t mod=nent-nmodules; modResetDigits();
-              nbytes += TD->GetEvent(mod);
+              nbytes += TD->GetEvent(mod+1);
               //nbytes += branch->GetEvent(mod); this works as well
 	      Int_t ndigits = ITSdigits->GetEntries();
 	      if (ndigits) printf("Found %d digits for module %d in det type %d \n",ndigits,mod,ich+1);
@@ -90,7 +90,7 @@ void ITSdigitsTest (Int_t evNumber1=0,Int_t evNumber2=0)
 	      */
 	      for (Int_t digit=0;digitUncheckedAt(digit);
-		printf("%d %d %d %d \n",ITSdigit->fCoord1,ITSdigit->fCoord2,ITSdigit->fSignal,ITSdigit->fTracks[0]);
+		printf("%d %d %d %d %d %d \n",ITSdigit->fCoord1,ITSdigit->fCoord2,ITSdigit->fSignal,ITSdigit->fTracks[0],ITSdigit->fTracks[1],ITSdigit->fTracks[2]);
 
 	      }
 	  }        
diff --git a/ITS/ITShuffman.C b/ITS/ITShuffman.C
new file mode 100644
index 00000000000..d51520507ef
--- /dev/null
+++ b/ITS/ITShuffman.C
@@ -0,0 +1,69 @@
+#include "iostream.h"
+
+void ITShuffman_f (Int_t evNumber1=0,Int_t evNumber2=0) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("stream.root");
+   if (!file) file = new TFile("stream.root");
+   file->ls();
+
+
+   AliITSInStream  *IStream;
+
+   char *path=gDirectory->GetPath();
+   printf("path %s\n",path);
+   
+
+   Int_t nkeys=gDirectory->GetNkeys();
+   printf("nkeys %d\n",nkeys);
+   char namecycle[40];
+
+   AliITSHTable *hufft=new AliITSHTable(256);
+   for (int i=1;i<=nkeys;i++) {
+     Int_t count=0;
+     Int_t count1=0;
+     Int_t count2=0;
+     Int_t count3=0;
+       sprintf(namecycle,"AliITSInStream;%d",i);
+       printf("namecycle %s\n",namecycle);
+       IStream=(AliITSInStream*)gDirectory->Get(namecycle);
+       UChar_t *str=IStream->Stream();
+       Int_t len=IStream->StreamLength();
+       //printf("str len %p %d\n",str,len);
+       for (int k=0;kGetFrequencies(len,str);
+   }
+
+   hufft->BuildHTable();
+
+   cout<<"END  test for InStream "<Close();   
+}
+
+
+
diff --git a/ITS/ITSmixedpoints.C b/ITS/ITSmixedpoints.C
new file mode 100644
index 00000000000..d136b7c66e1
--- /dev/null
+++ b/ITS/ITSmixedpoints.C
@@ -0,0 +1,102 @@
+#include "iostream.h"
+
+void ITSmixedpoints (Int_t evNumber1=0,Int_t evNumber2=0,Int_t nsignal  =25, Int_t size=-1) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   printf("file %p\n",file);
+   if (file) file->Close(); 
+   file = new TFile("galice.root","UPDATE");
+   file->ls();
+
+   printf ("I'm after Map \n");
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+       gAlice = (AliRun*)file->Get("gAlice");
+       if (gAlice) printf("AliRun object found on file\n");
+       if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+   printf ("I'm after gAlice \n");
+   
+   AliITS *ITS  = (AliITS*) gAlice->GetModule("ITS");
+   if (!ITS) return;
+
+   // set the simulation models
+   AliITSgeom *geom = ITS->GetITSgeom();
+
+   // SPD - simulation slow points
+
+   AliITSDetType *iDetType=ITS->DetType(0);
+   AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
+   AliITSresponseSPD *res0 = (AliITSresponseSPD*)iDetType->GetResponseModel();
+   AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
+   ITS->SetSimulationModel(0,sim0);
+
+   // SPD - cluster finder
+   AliITSDetType *iDetType=ITS->DetType(0);
+   AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
+   TClonesArray *dig0  = ITS->DigitsAddress(0);
+   TClonesArray *recp0  = ITS->ClustersAddress(0);
+   AliITSClusterFinderSPD *rec0=new AliITSClusterFinderSPD(seg0,dig0,recp0);
+   ITS->SetReconstructionModel(0,rec0);
+
+   // SDD+SSD - fast poinst
+
+   AliITSsimulationFastPoints *sim = new AliITSsimulationFastPoints();
+
+   for (Int_t i=1;i<3;i++) {
+       ITS->SetSimulationModel(i,sim);
+   }
+
+//
+// Event Loop
+//
+  Int_t nbgr_ev=0;
+
+   for (int ev=evNumber1; ev<= evNumber2; ev++) {
+       Int_t nparticles = gAlice->GetEvent(ev);
+       cout << "event         " <DigitsToRecPoints(ev,last_entry,"SPD");
+       ITS->HitsToFastRecPoints(ev,bgr_ev,size," ","SDD"," ");
+       ITS->HitsToFastRecPoints(ev,bgr_ev,size," ","SSD"," ");
+   } // event loop 
+
+   file->Close();
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ITS/ITSreadClustTest.C b/ITS/ITSreadClustTest.C
new file mode 100644
index 00000000000..8fd73020c17
--- /dev/null
+++ b/ITS/ITSreadClustTest.C
@@ -0,0 +1,105 @@
+#include "iostream.h"
+
+void ITSreadClustTest (Int_t evNumber1=0,Int_t evNumber2=0) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   if (!file) file = new TFile("galice.root");
+   file->ls();
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+      gAlice = (AliRun*)file->Get("gAlice");
+      if (gAlice) printf("AliRun object found on file\n");
+      if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+ 
+//
+//   Loop over events 
+//
+   Int_t Nh=0;
+   Int_t Nh1=0;
+   for (int nev=0; nev<= evNumber2; nev++) {
+     Int_t nparticles = gAlice->GetEvent(nev);
+     cout << "nev         " << nev <TreeH();
+     Int_t ntracks = TH->GetEntries();
+     cout<<"ntracks "<GetModule("ITS");
+   if(!ITS) return;
+   TClonesArray *Particles = gAlice->Particles();
+
+     ITS->GetTreeC(nev);
+     TTree *TC=ITS->TreeC();
+     Int_t nent=TC->GetEntries();
+     printf("Found %d entries in the tree (must be one per module per event!)\n",nent);
+   
+     for (Int_t idet=0;idet<3;idet++) {
+
+       TClonesArray *ITSclu  = ITS->ClustersAddress(idet);
+
+          if (idet != 0) continue;
+	  for (Int_t mod=0; modResetClusters();
+              TC->GetEvent(mod);
+	      Int_t ncl = ITSclu->GetEntries();
+	      if (ncl) printf("Found %d clusters for module %d in det type %d \n",nrecp,mod,idet);
+
+	      if (!ncl) continue;
+
+	      for (Int_t icl=0;iclUncheckedAt(icl);
+		printf("%d %d %f %f %f\n",ITSclust->NclZ(),ITSclust->NclX(),ITSclust->Q(),ITSclust->X(),ITSclust->Z());
+		/*
+	      for (Int_t icl=0;iclUncheckedAt(icl);
+		printf("%d %d %f %f %f\n",ITSclust->Anodes(),ITSclust->Samples(),ITSclust->Q(),ITSclust->X(),ITSclust->Z());
+		*/
+
+	      }
+	  }        
+     }
+
+   }   // event loop 
+
+     cout<<"END  test for clusters "<Close();   
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/ITS/ITSreadRecPointsTest.C b/ITS/ITSreadRecPointsTest.C
new file mode 100644
index 00000000000..a63e69a6ef5
--- /dev/null
+++ b/ITS/ITSreadRecPointsTest.C
@@ -0,0 +1,83 @@
+#include "iostream.h"
+
+void ITSreadRecPointsTest (Int_t evNumber1=0,Int_t evNumber2=0) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   if (!file) file = new TFile("galice.root");
+   file->ls();
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+      gAlice = (AliRun*)file->Get("gAlice");
+      if (gAlice) printf("AliRun object found on file\n");
+      if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+ 
+//
+//   Loop over events 
+//
+   Int_t Nh=0;
+   Int_t Nh1=0;
+   for (int nev=0; nev<= evNumber2; nev++) {
+     Int_t nparticles = gAlice->GetEvent(nev);
+     cout << "nev         " << nev <TreeH();
+     Int_t ntracks = TH->GetEntries();
+     cout<<"ntracks "<GetModule("ITS");
+     if (!ITS) return;
+     TClonesArray *Particles = gAlice->Particles();
+     TTree *TR = gAlice->TreeR();
+     Int_t nent=TR->GetEntries();
+     printf("Found %d entries in the tree (must be one per module per event!)\n",nent);
+
+     TClonesArray *ITSrec  = ITS->RecPoints();
+     for (Int_t mod=0; modResetRecPoints();
+       TR->GetEvent(mod+1);
+       Int_t nrecp = ITSrec->GetEntries();
+       if (nrecp) printf("Found %d rec points for module %d \n",nrecp,mod);
+       if (!nrecp) continue;
+
+       for (Int_t irec=0;irecUncheckedAt(irec);
+		printf("%d %f %f %d %d %d\n",irec,recp->GetX(),recp->GetZ(),recp->fTracks[0],recp->fTracks[1],recp->fTracks[2]);
+
+       }
+     }        
+   }   // event loop 
+   
+     cout<<"END  test for rec points "<Close();   
+}
+
+
+
diff --git a/ITS/ITSreadTest.C b/ITS/ITSreadTest.C
new file mode 100644
index 00000000000..6f37e37209c
--- /dev/null
+++ b/ITS/ITSreadTest.C
@@ -0,0 +1,124 @@
+#include "iostream.h"
+
+void ITSreadTest (Int_t evNumber1=0,Int_t evNumber2=0) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   if (!file) file = new TFile("galice.root");
+   file->ls();
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+      gAlice = (AliRun*)file->Get("gAlice");
+      if (gAlice) printf("AliRun object found on file\n");
+      if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+ 
+//
+//   Loop over events 
+//
+   Int_t Nh=0;
+   Int_t Nh1=0;
+   for (int nev=0; nev<= evNumber2; nev++) {
+     Int_t nparticles = gAlice->GetEvent(nev);
+     cout << "nev         " << nev <TreeH();
+     Int_t ntracks = TH->GetEntries();
+     cout<<"ntracks "<GetModule("ITS");
+   if(!ITS) return;
+   TClonesArray *Particles = gAlice->Particles();
+
+     // fill modules with sorted by module hits
+     Int_t nmodules;
+     ITS->InitModules(-1,nmodules); 
+     ITS->FillModules(nev,-1,nmodules," "," ");
+     //get pointer to modules array
+     TObjArray *ITSmodules = ITS->GetModules();
+     AliITShit *itsHit;
+
+     TTree *TR=gAlice->TreeR();
+     Int_t nentr=TR->GetEntries();
+     printf("Found %d entries in the TreeR (must be one per module per event!)\n",nentr);
+     TClonesArray *ITSrecpoints  = ITS->RecPoints();
+
+     // get the Tree for clusters
+     ITS->GetTreeC(nev);
+     TTree *TC=ITS->TreeC();
+     Int_t nent=TC->GetEntries();
+     printf("Found %d entries in the tree (must be one per module per event!)\n",nent);
+   
+     for (Int_t idettype=0;idettype<3;idettype++) {
+
+       TClonesArray *ITSclusters  = ITS->ClustersAddress(idettype);
+       //printf ("ITSclusters %p \n",ITSclusters);
+
+          if (idettype != 1) continue;
+	  for (Int_t mod=0; modAt(mod);
+	      Int_t nhits = itsModule->GetNhits();
+              printf("module nhits %d %d\n",mod,nhits);
+	      for (Int_t ihit=0;ihitGetHit(ihit);
+                printf("ihit x y z %d %f %f %f\n",ihit,itsHit->GetXG(),itsHit->GetYG(),itsHit->GetZG());
+	      }
+              
+       
+              ITS->ResetClusters();
+              TC->GetEvent(mod);
+	      Int_t nclust = ITSclusters->GetEntries();
+	      if (nclust) printf("Found %d clust for module %d in det type %d \n",nclust,mod,idettype);
+	      if (!nclust) continue;
+
+              ITS->ResetRecPoints();
+              TR->GetEvent(mod+1);
+	      Int_t nrecp = ITSrecpoints->GetEntries();
+	      if (nrecp) printf("Found %d recp for module %d  \n",nrecp,mod);
+
+	      for (Int_t clust=0;clustUncheckedAt(clust);
+		printf("recp %d %f %f %f\n",clust,ITSrecp->GetX(),ITSrecp->GetZ(),ITSrecp->GetQ());
+		ITSclust   = (AliITSRawClusterSDD*)ITSclusters->UncheckedAt(clust);
+		printf("clust %d %f %f %f\n",clust,ITSclust->X(),ITSclust->Z(),ITSclust->Q());
+	      }
+	  }        
+     }
+
+     ITS->ClearModules();
+
+   }   // event loop 
+
+     cout<<"END  test for clusters and hits "<Close();   
+}
+
+
+
diff --git a/ITS/ITSstream.C b/ITS/ITSstream.C
new file mode 100644
index 00000000000..54d72f481a4
--- /dev/null
+++ b/ITS/ITSstream.C
@@ -0,0 +1,68 @@
+#include "iostream.h"
+
+void ITSstream (Int_t evNumber1=0,Int_t evNumber2=0) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("stream.root");
+   if (!file) file = new TFile("stream.root");
+   file->ls();
+
+// Get AliRun object from file or create it if not on file
+
+   /*
+   if (!gAlice) {
+      gAlice = (AliRun*)file->Get("gAlice");
+      if (gAlice) printf("AliRun object found on file\n");
+      if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+   */
+
+   AliITSInStream  *IStream;
+
+   char *path=gDirectory->GetPath();
+   printf("path %s\n",path);
+   
+
+   Int_t nkeys=gDirectory->GetNkeys();
+   printf("nkeys %d\n",nkeys);
+   char namecycle[40];
+
+   for (int i=1;i<=nkeys;i++) {
+     //sprintf(namecycle,"%s%d",GetName(),i);
+       sprintf(namecycle,"AliITSInStream;%d",i);
+       printf("namecycle %s\n",namecycle);
+       IStream=(AliITSInStream*)gDirectory->Get(namecycle);
+       //Char_t *str=IStream->Stream();
+       UChar_t *str=IStream->Stream();
+       Int_t len=IStream->StreamLength();
+       printf("str len %p %d\n",str,len);
+       for (int k=0;k 0) printf("i,k,elem %d %d %d\n",i,k,elem);
+       }
+   }
+
+     cout<<"END  test for InStream "<Close();   
+}
+
+
+
diff --git a/ITS/Makefile b/ITS/Makefile
index 6719f0167da..f4e2c16270c 100644
--- a/ITS/Makefile
+++ b/ITS/Makefile
@@ -9,27 +9,29 @@ PACKAGE = ITS
 
 # C++ sources
 
-SRCS          = AliITS.cxx \
-AliITSv1.cxx AliITSv3.cxx AliITSv5.cxx\
-AliITShit.cxx \
-AliITSgeom.cxx AliITSgeomSPD.cxx AliITSgeomSDD.cxx AliITSgeomSSD.cxx \
-AliITSmodule.cxx AliITSsimulationFastPoints.cxx\
-AliITSsimulation.cxx AliITSsimulationSPD.cxx \
-AliITSsimulationSDD.cxx AliITSetfSDD.cxx\
-AliITSsimulationSSD.cxx AliITSdcsSSD.cxx\
-AliITSdictSSD.cxx \
-AliITSdigit.cxx \
-AliITSRawCluster.cxx \
-AliITSstatistics.cxx AliITSstatistics2.cxx \
-AliITSMap.cxx \
-AliITSsegmentationSPD.cxx  AliITSsegmentationSDD.cxx AliITSsegmentationSSD.cxx\
-AliITSresponseSPD.cxx  AliITSresponseSDD.cxx AliITSresponseSSD.cxx\
-AliITSClusterFinder.cxx \
-AliITSClusterFinderSPD.cxx AliITSClusterFinderSDD.cxx AliITSRawData.cxx \
-AliITSHuffman.cxx \
-AliITSClusterFinderSSD.cxx AliITSclusterSSD.cxx AliITSpackageSSD.cxx \
-AliITSDetType.cxx \
-AliITSgeomSPD300.cxx AliITSgeomSPD425.cxx
+SRCS          = AliITS.cxx AliITSv1.cxx AliITSv3.cxx AliITSv5.cxx \
+		AliITSvtest.cxx AliITShit.cxx AliITSDetType.cxx \
+		AliITSgeom.cxx AliITSgeomSPD.cxx AliITSgeomSDD.cxx \
+		AliITSgeomSSD.cxx AliITSmodule.cxx \
+		AliITSsimulationFastPoints.cxx \
+		AliITSsimulationFastPointsV0.cxx AliITSsimulation.cxx \
+		AliITSsimulationSPD.cxx AliITSsimulationSDD.cxx \
+		AliITSetfSDD.cxx AliITSsimulationSSD.cxx AliITSdcsSSD.cxx \
+		AliITSdigit.cxx AliITSRawCluster.cxx AliITSRecPoint.cxx \
+		AliITStrack.cxx AliITSMap.cxx AliITSMapA1.cxx AliITSMapA2.cxx \
+		AliITSsegmentation.cxx AliITSsegmentationSPD.cxx \
+		AliITSsegmentationSDD.cxx AliITSsegmentationSSD.cxx\
+		AliITSresponse.cxx AliITSresponseSPD.cxx \
+		AliITSresponseSDD.cxx AliITSresponseSSD.cxx \
+		AliITSClusterFinder.cxx AliITSClusterFinderSPD.cxx \
+		AliITSClusterFinderSDD.cxx AliITSRawData.cxx \
+		AliITSHuffman.cxx AliITSClusterFinderSSD.cxx \
+		AliITSclusterSSD.cxx AliITSpackageSSD.cxx \
+		AliITSdictSSD.cxx AliITSgeomSPD300.cxx AliITSgeomSPD425.cxx \
+		vertex.cxx AliITSstatistics.cxx AliITSstatistics2.cxx \
+		AnalysisITSAlignment.cxx  AliITSAlignmentTrack.cxx \
+		AliITSAlignmentModule.cxx 
+
 # Fortran sources
 
 FSRCS	       = 
@@ -94,3 +96,4 @@ include $(ALICE_ROOT)/conf/GeneralMacros
 
 -include tgt_$(ALICE_TARGET)/Make-depend 
 
+
diff --git a/ITS/SPD_ntuple.C b/ITS/SPD_ntuple.C
new file mode 100644
index 00000000000..76ffa033b0f
--- /dev/null
+++ b/ITS/SPD_ntuple.C
@@ -0,0 +1,329 @@
+void SPD_ntuple()
+{
+
+TFile *f = new TFile("SPD_his.root");
+//TH1F *Pix = (TH1F*)f->Get("Pix");
+   
+//gStyle->SetOptStat(1111111);
+gStyle->SetOptLogy();
+//TCanvas *c1 = new TCanvas("c1","SPD clusters",400,10,600,700);
+TCanvas *c2 = new TCanvas("c2","SPD clusters",400,10,600,700);
+//c1->Divide(2,2);
+c2->Divide(2,2);
+//c2->SetLogy();
+
+/////////////////////////  Ntuple analysis ///////////////////////////////
+
+// ntuple is created inside the hit loop for the hits in the cluster region;
+
+// ntuple1 is created after a finish of the hit loop if one or more hits
+// are in the cluster region;
+
+// ntuple2 is created befor the hit loop for all clusters;
+
+// -----------------------------------------------------------------------
+// lay       - number of ITS layer;
+// nx        - cluster size in the r*phi(x) direction;
+// nz        - cluster size in the z direction;
+// hitprim   - primary particle(hit) flag ( = 1 for primery particle);     
+// dx        - difference of hit(mediate) and reconstructed (from cluster)
+//             coordinates in r*phi(x) direction;
+// dz        - difference of hit(mediate) and reconstructed (from cluster)
+//             coordinates in z direction;
+// noverlaps - number of particles overlapping in one cluster;
+// noverprim - number of primary particles overlapping in one cluster;
+// qcl       - cluster charge in electron number  
+// -------------------------------------------------------------------------
+
+/*
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay == 1 && hitprim == 1");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay == 1 && hitprim == 1");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay == 2 && hitprim == 1");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay == 2 && hitprim == 1");
+*/
+
+/*      
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay == 1 && hitprim == 1");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dx","lay == 1 && hitprim == 1 && nx < 15");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay == 1 && hitprim == 1 && nx < 5");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dx","lay == 1 && hitprim == 1 && nx < 4");
+*/
+    
+      /*                  
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay==1&&hitprim==1&&dx>-150&&dx<150");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay==1&&hitprim==1&&dz>-500&&dz<500");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay==2&&hitprim==1&&dx>-150&&dx<150");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay==2&&hitprim==1&&dz>-500&&dz<500");
+      */
+/*
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay==1&&hitprim==1&&dx>-150&&dx<150&&nx<5");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay==1&&hitprim==1&&dz>-500&&dz<500&&nz<5");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay==2&&hitprim==1&&dx>-150&&dx<150&&nx<5");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay==2&&hitprim==1&&dz>-500&&dz<500&&nz<5");
+*/      
+/*
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay==1&&hitprim==1&&nx<4");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay==1&&hitprim==1&&nz<4");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(42);
+      ntuple->Draw("dx","lay==2&&hitprim==1&&nx<4");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple->SetFillColor(46);
+      ntuple->Draw("dz","lay==2&&hitprim==1&&nz<4");
+*/      
+
+/*                              
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("noverlaps","lay == 1");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("noverlaps","lay == 2");
+      
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("noverlaps","lay == 1 && noverprim > 0");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("noverlaps","lay == 2 && noverprim > 0");
+*/      
+/*        
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("noverprim","lay == 1");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("noverprim","lay == 2");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("noverprim","lay == 1 && noverprim > 1");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("noverprim","lay == 2 && noverprim > 1");
+*/       
+/*
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("qcl","lay == 1&&noverprim>0");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("qcl","lay == 2&&noverprim>0");
+*/
+
+      
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("nx","lay == 1&&noverprim>0");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("nx","lay == 2&&noverprim>0");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("nz","lay == 1 && noverprim>0");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("nz","lay == 2 && noverprim>0");
+
+            
+/*
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("dx","lay == 1&&noverprim>0");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("dx","lay == 2&&noverprim>0");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("dz","lay == 1 && noverprim>0");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("dz","lay == 2 && noverprim>0");
+*/
+
+      /*            
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("dx","lay == 1");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("dx","lay == 2");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(42);
+      ntuple1->Draw("dz","lay == 1");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple1->SetFillColor(46);
+      ntuple1->Draw("dz","lay == 2");
+      */
+      /*                
+c2->cd(1);
+gPad->SetFillColor(33);
+      ntuple2->SetFillColor(42);
+      ntuple2->Draw("nx","lay == 1");
+c2->cd(2);
+gPad->SetFillColor(33);
+      ntuple2->SetFillColor(46);
+      ntuple2->Draw("nz","lay == 1");
+c2->cd(3);
+gPad->SetFillColor(33);
+      ntuple2->SetFillColor(42);
+      ntuple2->Draw("nx","lay == 2");
+c2->cd(4);
+gPad->SetFillColor(33);
+      ntuple2->SetFillColor(46);
+      ntuple2->Draw("nz","lay == 2");
+      */
+      
+/////////////////////   Histogramm analysis  ////////////////////////
+
+      /*            
+c2->cd(1);
+gPad->SetFillColor(33);
+      Xres1->SetFillColor(42);
+      Xres1->Draw();
+c2->cd(2);
+gPad->SetFillColor(33);
+      Zres1->SetFillColor(42);
+      Zres1->Draw();
+c2->cd(3);
+gPad->SetFillColor(33);
+      Xres2->SetFillColor(46);
+      Xres2->Draw();
+c2->cd(4);
+gPad->SetFillColor(33);
+      Zres2->SetFillColor(46);
+      Zres2->Draw();
+      */
+      /*
+c2->cd(1);
+gPad->SetFillColor(33);
+      Nzpix1->SetFillColor(42);
+      Nzpix1->Draw();
+c2->cd(2);
+gPad->SetFillColor(33);
+      Nxpix1->SetFillColor(42);
+      Nxpix1->Draw();
+c2->cd(3);
+gPad->SetFillColor(33);
+      Nzpix2->SetFillColor(46);
+      Nzpix2->Draw();
+c2->cd(4);
+gPad->SetFillColor(33);
+      Nxpix2->SetFillColor(46);
+      Nxpix2->Draw();
+      */                         
+      
+      /*                          
+c2->cd(1);
+gPad->SetFillColor(33);
+      Zpix1->SetFillColor(42);
+      Zpix1->Draw();
+c2->cd(2);
+gPad->SetFillColor(33);
+      Xpix1->SetFillColor(46);
+      Xpix1->Draw();
+c2->cd(3);
+gPad->SetFillColor(33);
+      Zpix2->SetFillColor(42);
+      Zpix2->Draw();
+c2->cd(4);
+gPad->SetFillColor(33);
+      Xpix2->SetFillColor(46);
+      Xpix2->Draw();
+      */
+     
+      /*                       
+c2->Draw();   
+c2->Print("spd_res.ps");
+      */
+      /*                        
+c2->Draw();   
+c2->Print("spd_clsize.ps");
+      */    
+
+}
+
+
+
+
+
+
+
+
diff --git a/ITS/SPDclusterTest.C b/ITS/SPDclusterTest.C
new file mode 100644
index 00000000000..2bb984a70c6
--- /dev/null
+++ b/ITS/SPDclusterTest.C
@@ -0,0 +1,447 @@
+#include "iostream.h"
+
+void SPDclusterTest (Int_t evNumber1=0,Int_t evNumber2=0) 
+{
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and do some analysis.
+//   
+/////////////////////////////////////////////////////////////////////////
+
+// Dynamically link some shared libs
+
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   }
+
+// Connect the Root Galice file containing Geometry, Kine and Hits
+
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
+   if (!file) file = new TFile("galice.root");
+   file->ls();
+
+// Get AliRun object from file or create it if not on file
+
+   if (!gAlice) {
+      gAlice = (AliRun*)file->Get("gAlice");
+      if (gAlice) printf("AliRun object found on file\n");
+      if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+ 
+//
+//   Loop over events 
+//
+   Int_t Nh=0;
+   Int_t Nh1=0;
+   for (int nev=0; nev<= evNumber2; nev++) {
+     Int_t nparticles = gAlice->GetEvent(nev);
+     cout << "nev         " << nev <TreeH();
+     Int_t ntracks = TH->GetEntries();
+     cout<<"ntracks "<GetModule("ITS");
+   TClonesArray *Particles = gAlice->Particles();
+
+   if (ITS) {
+     // fill modules with sorted by module hits
+     Int_t nmodules;
+     ITS->InitModules(-1,nmodules); 
+     ITS->FillModules(nev,-1,evNumber2,nmodules," "," ");
+     //get pointer to modules array
+     TObjArray *ITSmodules = ITS->GetModules();
+     AliITShit *itsHit;
+
+     // get the Tree for clusters
+     ITS->GetTreeC(nev);
+     TTree *TC=ITS->TreeC();
+     Int_t nent=TC->GetEntries();
+     printf("Found %d entries in the tree (must be one per module per event!)\n",nent);
+   
+     for (Int_t idettype=0;idettype<3;idettype++) {
+
+       TClonesArray *ITSclusters  = ITS->ClustersAddress(idettype);
+       //printf ("ITSclusters %p \n",ITSclusters);
+
+          if (idettype != 0) continue;
+
+
+	  // ------------ Cluster and point analysis histogramms ------------
+
+	  TH1F *Nxpix1 = new TH1F("Nxpix1","Cluster size in x(r*phi) direction for layer 1",20,0.,20.);
+	  TH1F *Nxpix2 = new TH1F("Nxpix2","Cluster size in x(r*phi) direction for layer 2",20,0.,20.);
+	  TH1F *Nzpix1 = new TH1F("Nzpix1","Cluster size in z direction for layer 1",15,0.,15.);
+	  TH1F *Nzpix2 = new TH1F("Nzpix2","Cluster size in z direction for layer 2",15,0.,15.);
+	  TH1F *Xpix1 = new TH1F("Xpix1","Local x coordinate (mm) for layer 1",20,-2.,18.);
+	  TH1F *Xpix2 = new TH1F("Xpix2","Local x coordinate (mm) for layer 2",20,-2.,18.);
+	  TH1F *Zpix1 = new TH1F("Zpix1","Local z coordinate (mm) for layer 1",90,-2.,88.);
+	  TH1F *Zpix2 = new TH1F("Zpix2","Lolac z coordinate (mm) for layer 2",90,-2.,88.);
+
+	  TH1F *Xres1 = new TH1F("Xres1","Xrec and Xgen difference (micr) for layers 1",100,-200.,200.);
+	  TH1F *Xres2 = new TH1F("Xres2","Xrec and Xgen difference (micr) for layers 2",100,-200.,200.);
+	  TH1F *Zres1 = new TH1F("Zres1","Zrec and Zgen difference (micr) for layers 1",100,-800.,800.);
+	  TH1F *Zres2 = new TH1F("Zres2","Zrec and Zgen difference (micr) for layers 2",100,-800.,800.);
+
+
+	  // -------------- Create ntuples --------------------
+
+	  //  ntuple structures:
+
+	  struct {
+	    Int_t lay;
+	    Int_t nx;
+	    Int_t nz;
+	    Int_t hitprim;
+	    Int_t partcode;
+	    Float_t dx;
+	    Float_t dz;
+	    Float_t pmod;
+	  } ntuple_st;
+
+	  struct {
+	    Int_t lay;
+	    Int_t lad;
+	    Int_t det;
+	    Int_t nx;
+	    Int_t nz;
+	    Int_t noverlaps;
+	    Int_t noverprim;
+	    Float_t qcl;
+	    Float_t dx;
+	    Float_t dz;
+	  } ntuple1_st;
+
+
+	  struct {
+	    //	    Int_t lay;
+	    Int_t nx;
+	    Int_t nz;
+	  } ntuple2_st;
+
+
+	  ntuple = new TTree("ntuple","Demo ntuple");
+	  ntuple->Branch("lay",&ntuple_st.lay,"lay/I");
+	  ntuple->Branch("nx",&ntuple_st.nx,"nx/I");
+	  ntuple->Branch("nz",&ntuple_st.nz,"nz/I");
+	  ntuple->Branch("hitprim",&ntuple_st.hitprim,"hitprim/I");
+	  ntuple->Branch("partcode",&ntuple_st.partcode,"partcode/I");
+	  ntuple->Branch("dx",&ntuple_st.dx,"dx/F");
+	  ntuple->Branch("dz",&ntuple_st.dz,"dz/F");
+	  ntuple->Branch("pmod",&ntuple_st.pmod,"pmod/F");
+
+	  ntuple1 = new TTree("ntuple1","Demo ntuple1");
+	  ntuple1->Branch("lay",&ntuple1_st.lay,"lay/I");
+	  ntuple1->Branch("lad",&ntuple1_st.lad,"lad/I");
+	  ntuple1->Branch("det",&ntuple1_st.det,"det/I");
+	  ntuple1->Branch("nx",&ntuple1_st.nx,"nx/I");
+	  ntuple1->Branch("nz",&ntuple1_st.nz,"nz/I");
+	  ntuple1->Branch("qcl",&ntuple1_st.qcl,"qcl/F");
+	  ntuple1->Branch("noverlaps",&ntuple1_st.noverlaps,"noverlaps/I");
+	  ntuple1->Branch("noverprim",&ntuple1_st.noverprim,"noverprim/I");
+	  ntuple1->Branch("dx",&ntuple1_st.dx,"dx/F");
+	  ntuple1->Branch("dz",&ntuple1_st.dz,"dz/F");
+
+
+	  ntuple2 = new TTree("ntuple2","Demo ntuple2");
+	  //	  ntuple2->Branch("lay",&ntuple2_st.lay,"lay/I");
+	  ntuple2->Branch("nx",&ntuple2_st.nx,"nx/I");
+	  ntuple2->Branch("nz",&ntuple2_st.nz,"nz/I");
+
+// ------------------------------------------------------------------------
+
+	  // Module loop
+
+	  for (Int_t mod=0; modAt(mod);
+
+	      Int_t nhits = itsModule->GetNhits();
+              if(nhits) printf("module nhits %d %d\n",mod,nhits);
+	      if(!nhits) continue;
+     
+              ITS->ResetClusters();
+              TC->GetEvent(mod);
+	      Int_t nclust = ITSclusters->GetEntries();
+	      if (nclust) printf("Found %d clust for module %d in det type %d \n",nclust,mod,idettype);
+	      if (!nclust) continue;
+
+	      // cluster/hit loops
+
+	for (Int_t clu=0;cluUncheckedAt(clu);
+		printf("%d %d %f %f %f\n",itsclu->NclZ(),itsclu->NclX(),itsclu->Q(),itsclu->X(),itsclu->Z());
+
+		Int_t noverlaps = 0;
+		Int_t noverprim = 0;
+
+		Int_t clustersizex = itsclu->NclX();
+		Int_t clustersizez = itsclu->NclZ();
+		//       Int_t xstart = itsclu->XStart();
+		//       Int_t xstop = itsclu->XStop();
+		Int_t xstart = itsclu->XStartf();
+		Int_t xstop = itsclu->XStopf();
+		Float_t fxstart = xstart*50;
+		Float_t fxstop = (xstop+1)*50;
+		Float_t zstart = itsclu->ZStart();
+		Float_t zstop = itsclu->ZStop();
+		Int_t zend = itsclu->Zend();
+		Float_t clusterx = itsclu->X();
+		Float_t clusterz = itsclu->Z();
+		Float_t clusterQ = itsclu->Q();
+
+		ntuple2_st.nx = clustersizex;
+		ntuple2_st.nz = clustersizez;
+
+		ntuple2->Fill();
+
+		Int_t icl = 0;
+		Float_t dxprimlast = 10.e+6;
+		Float_t dzprimlast = 10.e+6;
+
+
+		//        if(module > 217 && module <  226) {
+                cout<<"mod,nclust,clu,Nxpix,Nzpix ="<GetHit(hit);
+
+		  Int_t hitlayer = itsHit->GetLayer();
+		  Int_t hitladder= itsHit->GetLadder();
+		  Int_t hitdet= itsHit->GetDetector();
+
+ 		  Int_t clusterlayer = hitlayer;
+		  Int_t clusterladder= hitladder;
+		  Int_t clusterdetector = hitdet;
+
+		  Int_t track = itsHit->fTrack;
+		  Int_t dray = 0;
+		  Int_t hitstat = itsHit->GetTrackStatus();
+
+
+		  Float_t zhit = 10000*itsHit->GetZL();
+		  Float_t xhit = 10000*itsHit->GetXL();
+
+		  if(abs(zhit) > SPDlength/2) {
+		    if(hitstat == 66) zhit0 = 1e+5;
+		    continue;
+		  }
+
+		  if(abs(xhit) > SPDwidth/2) {
+		    if(hitstat == 66) xhit0 = 1e+5;
+		    continue;
+		  }
+
+		  zhit += SPDlength/2;
+		  xhit += SPDwidth/2;
+		  Float_t yhit = 10000*itsHit->GetYL();
+
+		  if(hitlayer == 1 && hitstat == 66 && yhit > 71) {
+		    xhit0 = xhit;
+		    zhit0 = zhit;
+		  }
+		  if(hitlayer == 2 && hitstat == 66 && yhit < -71) {
+		    xhit0 = xhit;
+		    zhit0 = zhit;
+		  }
+
+		  if(hitstat != 68) continue; // Take only the hit if the last
+		  // track point went out from
+		  // the detector.
+
+		  if(xhit0 > 9e+4 || zhit0 > 9e+4) continue;
+
+
+		  Float_t xmed = (xhit + xhit0)/2;
+		  Float_t zmed = (zhit + zhit0)/2;
+
+		  Float_t xdif = xmed - clusterx;
+		  Float_t zdif = zmed - clusterz;
+
+      cout<<"clu,hit,xmed,fxstart,fxstop,zmed,zstart,zstop ="<= fxstart && xmed <= fxstop) && (zmed >= zstart && zmed <= zstop)) {
+
+        icl = 1;
+
+                //        part = (TParticle *)particles.UncheckedAt(track);
+                //        Int_t partcode = part->GetPdgCode();
+                //              Int_t primery = gAlice->GetPrimary(track);
+
+        Int_t parent = itsHit->GetParticle()->GetFirstMother();
+        Int_t partcode = itsHit->GetParticle()->GetPdgCode();
+
+//  partcode (pdgCode): 11 - e-, 13 - mu-, 22 - gamma, 111 - pi0, 211 - pi+
+//                      310 - K0s, 321 - K+, 2112 - n, 2212 - p, 3122 - lambda
+
+
+        Float_t px = itsHit->GetPXL();
+        Float_t py = itsHit->GetPYL();
+        Float_t pz = itsHit->GetPZL();
+        Float_t pmod = 1000*sqrt(px*px+py*py+pz*pz);
+
+              cout<<"track,partcode,pmod,parent ="< 0) noverprim = noverprim + 1;
+
+        if(hitprim > 0) {
+         dxprimlast = xdif;
+         dzprimlast = zdif;
+        }
+
+        // fill ntuple
+
+         ntuple_st.lay = hitlayer;
+         ntuple_st.nx = clustersizex;
+         ntuple_st.nz = clustersizez;
+         ntuple_st.hitprim = hitprim;
+         ntuple_st.partcode = partcode;
+         ntuple_st.dx = xdif;
+         ntuple_st.dz = zdif;
+         ntuple_st.pmod = pmod;
+
+         ntuple->Fill();
+
+      
+
+      if(hitprim > 0) {   // for primary particles
+        if(hitlayer == 1) {
+     cout<<"!!!!!! lay,hitprim,xdif,zdif ="<Fill(xdif);
+           Zres1->Fill(zdif);
+        }
+        if(hitlayer == 2) {
+     cout<<"!!!!!! lay,hitprim,xdif,zdif ="<Fill(xdif);
+           Zres2->Fill(zdif);
+        }
+      } // primery particles
+
+     } // end of cluster region
+   } // end of hit loop
+
+		
+      if(icl == 1) {
+
+        // fill ntuple1
+
+        //      ntuple1->Fill(clusterlayer,clustersizex,clustersizez,noverlaps,\
+noverprim,dx,dz);
+
+        if(noverlaps == 0) noverlaps = 1; // cluster contains one or more
+                                          // delta rays only
+
+         ntuple1_st.lay = clusterlayer;
+         ntuple1_st.lad = clusterladder;
+         ntuple1_st.det = clusterdetector;
+         ntuple1_st.nx = clustersizex;
+         ntuple1_st.nz = clustersizez;
+         ntuple1_st.qcl = clusterQ;
+         ntuple1_st.noverlaps = noverlaps;
+         ntuple1_st.noverprim = noverprim;
+         ntuple1_st.dx = dxprimlast;
+         ntuple1_st.dz = dzprimlast;
+
+         ntuple1->Fill();
+
+     } // icl = 1
+    } // cluster loop
+   } // module loop       
+  } // idettype loop
+ } // end if ITS
+} // event loop 
+
+
+   //  Write and Draw Histogramms and ntuples
+
+
+
+   TFile fhistos("SPD_his.root","RECREATE");
+
+   ntuple->Write();
+   ntuple1->Write();
+   ntuple2->Write();
+
+   Nxpix1->Write();
+   Nzpix1->Write();
+   Nxpix2->Write();
+   Nzpix2->Write();
+
+   Xpix1->Write();
+   Zpix1->Write();
+   Xpix2->Write();
+   Zpix2->Write();
+
+   Xres1->Write();
+   Zres1->Write();
+   Xres2->Write();
+   Zres2->Write();
+
+   fhistos.Close();
+   cout<<"!!! Histogramms and ntuples were written"<Divide(2,2);
+   c1->cd(1);
+   gPad->SetFillColor(33);
+         Xres1->SetFillColor(42);
+         Xres1->Draw();
+   c1->cd(2);
+   gPad->SetFillColor(33);
+         Zres1->SetFillColor(46);
+         Zres1->Draw();
+   c1->cd(3);
+   gPad->SetFillColor(33);
+         Xres2->SetFillColor(42);
+         Xres2->Draw();
+   c1->cd(4);
+   gPad->SetFillColor(33);
+         Zres2->SetFillColor(46);
+         Zres2->Draw();
+
+//     cout<<"END  test for clusters and hits "<Close();   
+}
+
+
+
diff --git a/ITS/vertex.cxx b/ITS/vertex.cxx
new file mode 100755
index 00000000000..dcbd3c68ee0
--- /dev/null
+++ b/ITS/vertex.cxx
@@ -0,0 +1,718 @@
+#include 
+#include 
+#include 
+#include "TMinuit.h"
+#include "TRandom.h"
+#include "TTree.h"
+#include "TClonesArray.h"
+#include "TProfile.h"
+#include "TH2.h"
+#include "TArray.h"
+#include "TCanvas.h"
+#include "TString.h"
+#include "AliRun.h"
+#include "AliITS.h"
+#include "AliITSgeom.h"
+#include "TParticle.h"
+#include "vertex.h"
+
+// Global in this file only. Needed for Minuit
+Int_t gstrt,gend;  // starting and ending bin values
+TH1D  *gH1;        // histogram to be fit.
+
+void FindVertexs(Int_t evnt,Float_t frac=1.0,Float_t len=16.82){
+
+      // Get pointers to Alice detectors and Hits containers
+      AliDetector  *ITS       = gAlice->GetDetector("ITS");
+      if(!ITS) return;          // error no ITS data exit
+//      TClonesArray *Particles = gAlice->Particles();
+      TClonesArray *ITShits   = ITS->Hits();
+      TTree        *TH        = gAlice->TreeH();
+      Int_t        ntracks    =  (Int_t)TH->GetEntries();
+//      ntracks = 10;
+
+      printf(" %d primary tracks in the file\n",ntracks);
+      // Array (stucture) of hits for the first and second layer
+      // this should be replaced with either clusters or digits
+      // when they are proporly defined.
+      Hit_tl *spd1 = new Hit_tl[ntracks];
+      Hit_tl *spd2 = new Hit_tl[ntracks];
+      Hit_tl **spdi = new Hit_tl*[ntracks];
+      Hit_tl **spdo = new Hit_tl*[ntracks];
+      for(Int_t i=0;ir;
+//	  if(ir;
+//      } // end for i
+//      printf("=%f i1max=%d\t=%f i2max=%d\n",
+//	     r1/Float_t(i1max),i1max,r2/Float_t(i2max),i2max);
+
+      vz = vertexSlow(spdi,i1max,spdo,i2max);
+
+      printf("Slow Sorted event=%d Zvertex=%f\n",evnt,vz);
+
+//      vz = vertex(spdi,i1max,spdo,i2max);
+
+//      printf("Phi sorted event=%d Zvertex=%f\n",evnt,vz);
+
+//      vz = vertexEta(spdi,i1max,spdo,i2max);
+
+//      printf("Eta sorted event=%d Zvertex=%f\n",evnt,vz);
+
+      return;
+}
+
+
+Bool_t L_SortPhi(const Hit_tl *s1,const Hit_tl *s2){
+  // Phi sorting function for qsort.
+   Float_t a;
+
+   a = s1->phir - s2->phir;
+   if(a<0.0) return kTRUE;
+   if(a>0.0) return kFALSE;
+   a = s1->etar - s2->etar;
+   if(a<0.0) return kTRUE;
+   if(a>0.0) return kFALSE;
+   return kFALSE;
+}
+
+Bool_t L_SortEta(const Hit_tl *s1,const Hit_tl *s2){
+  // Eta sorting function for qsort.
+   Float_t a;
+
+   a = s1->etar - s2->etar;
+   if(a<0.0) return kTRUE;
+   if(a>0.0) return kFALSE;
+   a = s1->phir - s2->phir;
+   if(a<0.0) return kTRUE;
+   if(a>0.0) return kFALSE;
+   return kFALSE;
+}
+
+void hpsortPhi(Hit_tl **ra,Int_t n){
+   Int_t i,ir,j,l;
+   Hit_tl *rra;
+
+   if(n<2) return;
+
+   l  = ((n-1) >> 1) +1; // devide 2 + 1
+   ir = n-1;
+   for(;;){
+     if(l>0){
+        rra = ra[--l];  // decrament first
+     }else{
+        rra    = ra[ir];
+        ra[ir] = ra[0];
+        if(--ir == 0){  // decrament first
+           ra[0] = rra;
+           break;
+        } // if --ra == 0 
+     } // end l>0 
+     i = l;
+     j = l+1;
+     while(j<=ir){
+        if( j> 1) +1; // devide 2 + 1
+   ir = n-1;
+   for(;;){
+     if(l>0){
+        rra = ra[--l];  // decrament first
+     }else{
+        rra    = ra[ir];
+        ra[ir] = ra[0];
+        if(--ir == 0){  // decrament first
+           ra[0] = rra;
+           break;
+        } // if --ra == 0 
+     } // end l>0 
+     i = l;
+     j = l+1;
+     while(j<=ir){
+        if( jtrack = track;
+    spd[i]->n     = nhits;
+    spd[i]->lad   = id[1];
+    spd[i]->det   = id[2];
+    spd[i]->x     = x;
+    spd[i]->y     = y;
+    spd[i]->z     = z;
+    spd[i]->r     = r;
+    spd[i]->phi   = phi;
+    spd[i]->eta   = eta;
+
+    zr   = dz    * Float_t(Int_t(z   /   dz)) + 0.5*dz;
+    rphi = drphi * Float_t(Int_t(rphi/drphi)) + 0.5*drphi;
+
+    spd[i]->xr   =  cos(phi)*rphi/r;
+    spd[i]->yr   = -sin(phi)*rphi/r;
+    spd[i]->zr   = zr;
+    spd[i]->phir = rphi/r;
+    spd[i]->etar = -0.5*tan(0.5*atan2(r,zr));
+
+    nspd++;
+    return;
+}
+
+void HitsToV(Hit_tl **spdi,Int_t &nspdi,Hit_tl **spdo,Int_t &nspdo,
+	    Int_t ntracks,TTree *TH,TClonesArray *ITShits,
+	     Float_t fraction=1.0,Float_t len=16.82){
+    Int_t     i,t,h,n,nb,nhits,id[4],idold[4],Iseed,ieta=0,itrk=0,ieta2=0;
+    Float_t   x[3],xb[3],xl[3];
+    AliITShit *itsHit;
+    TClonesArray *Part = gAlice->Particles();
+    TParticle *part;
+
+    nspdi = nspdo = 0;
+
+    idold[0] = idold[1] = idold[2] = idold[3] = 0;
+    xb[0]    = xb[1]    = xb[2]    = 0.0;
+    n = 0;
+    Iseed = time(0);
+    printf("HitsToV: Iseed=%d fraction=%f Pixel length=%fcm\n",
+	   Iseed,fraction,len);
+    gRandom->SetSeed(Iseed);
+//    printf("HitsToV: gRandom->Rndm(1)=%f\n",gRandom->Rndm(1));
+    for(t=0;tRndm(1)) continue; // skip some tracks
+	itrk++;
+	gAlice->ResetHits();
+	nb       = TH->GetEvent(t);
+	nhits    = ITShits->GetEntriesFast();
+	for(h=0;hUncheckedAt(h);
+	    itsHit->GetDetectorID(id[0],id[1],id[2]); id[3]=t;
+	    itsHit->GetPositionG(x[0],x[1],x[2]);
+	    itsHit->GetPositionL(xl[0],xl[1],xl[2]);
+	    if(h==0){
+		part = (TParticle *) (Part->UncheckedAt(itsHit->GetTrack()));
+		if(TMath::Abs(part->Eta())<=1.0) ieta++;
+		if(TMath::Abs(part->Eta())<=0.5) ieta2++;
+	    } // end if h==0
+	    if(TMath::Abs(x[2]/len) >= 1.0) continue;
+	    if(x[0]==0.0&&x[1]==0.0){
+		printf("Hitsto: t=%d h=%d/%d id=%d,%d,%d x=%f,%f,%f\n",
+		       t,h,nhits,id[0],id[1],id[2],x[0],x[1],x[2]); 
+		continue;
+	    } // end if x[0]==x[1]==0.0
+	    if(!(id[0]==idold[0]&&id[1]==idold[1]&&
+		 id[2]==idold[2]&&id[3]==idold[3])){
+		if(!(n<=0 || (xb[0]==0.0&&xb[1]==0.0))){
+		    for(i=0;i<3;i++) xb[i]   /= Float_t(n);
+		    if(idold[0]==1){
+			fillStructure(spdi,nspdi,xb,idold,t,n);
+		    }
+		    if(idold[0]==2){
+			fillStructure(spdo,nspdo,xb,idold,t,n);
+		    }
+		    if(nspdi>ntracks || nspdo>ntracks){
+			printf("Hitsto: fill error,"
+			       " nspdi=%d nspdo=%d ntracks=%d\n",
+			       nspdi,nspdo,ntracks);
+		    } // end if fill error
+		} // end if n>0
+		for(i=0;i<4;i++) idold[i] = id[i];
+		for(i=0;i<3;i++) xb[i]    = 0.0;
+		n = 0;
+	    } // end if id != idold
+	    for(i=0;i<3;i++) xb[i] += x[i];
+	    n++;
+	} // end for h
+    } // end for t
+    printf("exiting HitsToV: %d primary tracks in eta=+-1\n",ieta);
+    printf("exiting HitsToV: %d primary tracks #2 in eta=+-0.5\n",ieta2);
+    printf("exiting HitsToV: %d primary tracks in file used\n",itrk);
+    return;
+}
+
+Float_t vertex(Hit_tl **spdi,Int_t i1max,Hit_tl **spdo,Int_t i2max){
+   Float_t r1    = 3.910078; // radius at which hit is from beam axis for spd1
+   Float_t r2    = 6.955933; // radius at which hit is from beam axis for spd2
+   Float_t DPhi  = 0.005;    // maximum allowed difference in phi angle
+   Float_t DZ    = 12.5;      // maximum allowed difference in z position
+   Float_t avt   = 0.0;
+   Int_t   nbinx = 2000;
+   Int_t   start = 0;
+   Bool_t  mod   = kFALSE;
+   Int_t   i,j;
+   Float_t zv,av,su,i0,i1,i2,x0,x1,dphi,dz;
+   Float_t PI2 = 2.0*TMath::Pi();
+   Float_t PI  = TMath::Pi();
+
+   // sort according to phi.
+   hpsortPhi(spdi,i1max);
+   hpsortPhi(spdo,i2max);
+
+   // find best vertex allong z.
+   TH2S *Pvzphi   = new TH2S("Pvzphi","Phi: Posible Z vertecies vs. Phi",
+                              nbinx,-1.0,1.0,32,0.0,PI2);
+   Pvzphi->Sumw2(); // collect good statitics
+   TH1F *Pvzfl   = new TH1F("Pvzfl","Phi: Posible Z vertecies flattened",
+			 nbinx,-1.0,1.0);
+   Pvzfl->Sumw2();
+   TH1F *Pvztr  = new TH1F("Pvztr","Phi: Z Vertex found for True Tracks",
+			 nbinx,-1.0,1.0);
+   Pvztr->Sumw2(); // collect good statitics
+
+   for(i=0;ir==0.0) {printf("spdi[%d]->r=0.0\n",i);continue;}
+       for(;spdo[start]->phirphir-1.5*DPhi;start++);
+       for(j=start;(spdo[j]->phir < spdi[i]->phir+DPhi) && (jphir - spdi[i]->phir); if(dphi>PI) dphi -= PI;
+	   dz   = fabs(spdo[j]->zr   - spdi[i]->zr);
+	   if(dphi>DPhi) continue;
+           if(dz>DZ)     continue; // If outside dz range skip it
+	   r1   = spdi[i]->r;
+	   r2   = spdo[j]->r;
+	   if(r2-r1!=0.0) zv   = (r2*spdi[i]->zr - r1*spdo[j]->zr)/(r2-r1);
+	   else{
+	       printf("vertex: spdi[%d]->r=%f = spdo[%d]->r=%f\n",i,r1,j,r2);
+	       continue;
+	   } // end if else r2-r1!=0.0
+	   Pvzphi->Fill(zv,spdi[i]->phir);
+	   Pvzfl->Fill(zv);
+	   if(spdi[i]->track == spdo[j]->track) Pvztr->Fill(zv);
+       } // end for j
+   } // end for i
+
+   TH1D *Pvzdef  = Pvzphi->ProjectionX("Phi: Posible Z vertecies",1,nbinx,"E");
+
+   i0 = Pvzfl->GetBinContent(1);
+   x0 = Float_t(1);
+   i1 = Pvzfl->GetBinContent(nbinx);
+   x1 = Float_t(nbinx);
+   su = x0-x1; if(su==0.0) return -200.0;
+   su = (i0-i1)/su;
+   x0 = x0-su*i0;
+   x1 = su;
+   for(i=1;i<=nbinx;i++){
+      su = x1*Float_t(i) + x0;
+      Pvzfl->AddBinContent(i,-su);
+   } // end for i
+
+   printf("Phi:            mean=%f RMS=%f w2=%f\n",
+               Pvzdef->GetMean(),Pvzdef->GetRMS(),Pvzdef->GetSumOfWeights());
+   printf("Phi: Flattened mean=%f RMS=%f w2=%f\n",
+	          Pvzfl->GetMean(),Pvzfl->GetRMS(),Pvzfl->GetSumOfWeights());
+
+   av = 3.0 * Pvzfl->Integral(1,nbinx)/Float_t(nbinx);
+   printf("Phi: Flattened av=%f Pvzfl->Max=%f nbinx=%d\n",
+	  av,Pvzfl->GetMaximum(),nbinx);
+
+   su  = 0.0;
+   avt = 0.0;
+   i1  = Pvzfl->GetBinContent(1);
+   i2  = Pvzfl->GetBinContent(2);
+   for(i=2;iGetBinContent(i+1); // new i+1 value
+       if(i1 > av && (i0 > av || i2 > av ) ){
+	   if(!mod) mod = kTRUE;
+       } else if(mod) break;
+       if(mod){ // inside peak
+	   su  += i1;
+	   avt += i1 * Pvzfl->GetXaxis()->GetBinCenter(i);
+       } // end if mod
+   } // end for i
+
+   if(su!=0.0) zv = avt/su;
+   else        zv = -100.0; // an unphysical value
+
+   TCanvas *c0 = new TCanvas("c0","Alice ITS vertex finder", 400,10,600,700);
+   Pvzphi->Draw("col");
+   c0->Print("vertex5_P_vz_phi.ps");
+   Pvzdef->Draw();
+   c0->Print("vertex5_P_vz_def.ps");
+   Pvzfl->Draw();
+   c0->Print("vertex5_P_vz_flat.ps");
+   Pvztr->Draw();
+   c0->Print("vertex5_P_vz_true.ps");
+
+   return zv;
+}
+
+void Chi2Gauss(Int_t &npar,Double_t *gin,Double_t &f,
+	       Double_t *par,Int_t iflag){
+    Double_t chi2 = 0.0;
+    Double_t delta,h,x,eh;
+
+    for(Int_t i=gstrt;iGetBinContent(i);
+	eh = TMath::Sqrt(h);
+	if(eh <= 0.0) eh = 1.0;
+	x = gH1->GetXaxis()->GetBinCenter(i);
+	delta = (h - par[0]*TMath::Gaus(x,par[1],par[2]) - par[3])/eh;
+	chi2 += delta*delta;
+    } // end for i
+    f = chi2;
+    return;
+}
+
+Float_t vertexSlow(Hit_tl **spdi,Int_t i1max,Hit_tl **spdo,Int_t i2max){
+   Float_t r1    = 3.910078; // radius at which hit is from beam axis for spd1
+   Float_t r2    = 6.955933; // radius at which hit is from beam axis for spd2
+   Float_t DPhi  = 0.005;    // maximum allowed difference in phi angle
+   Float_t BDphi;
+   Float_t DZ    = 12.5;      // maximum allowed difference in z position
+   Float_t avt   = 0.0;
+   Int_t   nbinx = 2000;
+   Int_t   nbst;
+   Bool_t  mod   = kFALSE;
+   Int_t   i,j;
+   Float_t zv,av,su,i0,i1,i2,x0,x1,dphi,dz;
+   Float_t PI2 = 2.0*TMath::Pi();
+   Float_t PI  = TMath::Pi();
+
+   if(i1max<=0||i2max<=0) return -1.0E10;
+
+   // find best vertex allong z.
+   TH2S *Svzphi  = new TH2S("Svzphi","Slow: Posible Z vertecies vs. Phi",
+			    nbinx,+0.0,10.0,32,0.0,PI2);
+   Svzphi->Sumw2(); // collect good statitics
+   TH2S *Svzdphi  = new TH2S("Svzdpii","Slow: Posible Z vertecies vs. DPhi",
+			     200,+4.0,6.0,20,0.0,10*DPhi);
+   Svzdphi->Sumw2(); // collect good statitics
+   TH1F *Svzfl  = new TH1F("Svzfl","Slow: Posible Z vertecies Flattened",
+			    nbinx,+4.0,6.0);
+   Svzfl->Sumw2();
+   TH1F *Svztr = new TH1F("Svztr","Slow: Z Vertex found by True Tracks",
+			  nbinx,+4.0,6.0);
+   Svztr->Sumw2(); // collect good statitics
+
+   printf("Svertex: i1max=%d i2max=%d\n",i1max,i2max);
+
+   for(i=0;iphir - spdi[i]->phir); if(dphi>PI) dphi -= PI;
+       dz   = fabs(spdo[j]->zr   - spdi[i]->zr);
+       r1   = spdi[i]->r;
+       r2   = spdo[j]->r;
+       if(r2-r1!=0.0) zv   = (r2*spdi[i]->zr - r1*spdo[j]->zr)/(r2-r1);
+       else{
+	   printf("vertex_slow: spdi[%d]->r=%f = spdo[%d]->r=%f\n",i,r1,j,r2);
+	   continue;
+       } // end if else r1-r2!=0.0
+//       if(j<10&&i<10) printf("zv=%e dphi=%e,r1=%e,r2=%e,dz=%e\n",
+//			     zv,dphi,r1,r2,dz);
+       Svzdphi->Fill(zv,dphi);
+       if(dphi>DPhi) continue; // If outside DPhi (momentum) range, skip it.
+       if(dz>DZ)     continue; // If outside dz range, skip it.
+       Svzphi ->Fill(zv,spdi[i]->phir);
+       Svzfl->Fill(zv);
+       if(spdi[i]->track == spdo[j]->track) Svztr->Fill(zv);
+   } // end for i,j
+
+   TH1D *Svzdef = Svzphi->ProjectionX("Slow: Posible Z vertecies",0,nbinx,"E");
+
+   i0 = Svzfl->GetBinContent(1);
+   x0 = Float_t(1);
+   i1 = Svzfl->GetBinContent(nbinx);
+   x1 = Float_t(nbinx);
+   su = x0-x1; if(su==0.0) return -200.0;
+   su = (i0-i1)/su;
+   x0 = x0-su*i0;
+   x1 = su;
+   for(i=1;i<=nbinx;i++){
+      su = x1*Float_t(i) + x0;
+      Svzfl->AddBinContent(i,-su);
+   } // end for i
+
+   printf("Slow:           mean=%f RMS=%f w2=%f\n",
+	  Svzdef->GetMean(),Svzdef->GetRMS(),Svzdef->GetSumOfWeights());
+   printf("Slow: Flattened mean=%f RMS=%f w2=%f\n",
+	  Svzfl->GetMean(),Svzfl->GetRMS(),Svzfl->GetSumOfWeights());
+
+   av = 3.0 * Svzfl->Integral(1,nbinx)/Float_t(nbinx);
+   printf("Slow: Flattened av=%f Tvxps->Max=%f nbinx=%d\n",
+	  av,Svzfl->GetMaximum(),nbinx);
+
+   {// find best dPhi that masimizes the signal/noise ration.
+       Float_t sn=0.0,sig=0.0,nois=0.0,ns;
+       Int_t   iend = Svzdphi->GetYaxis()->GetNbins();
+       Int_t   jend = Svzdphi->GetXaxis()->GetNbins();
+       Int_t   ipeak = Svzdphi->GetXaxis()->FindBin(Svzdef->GetMean());
+       nbst = 0;
+       for(i=0;i<=iend;i++){
+	   sig += Svzdphi->GetCellContent(ipeak,i);
+	   ns   = 0.0;
+	   for(j=1;j<6;j++) ns += Svzdphi->GetCellContent(j,i);
+	   for(j=jend-6;jGetCellContent(j,i);
+	   nois += 0.1*ns;
+	   if(nois<=0.0) continue;
+	   if((sig-nois)/nois>sn){
+	       sn = (sig-nois)/nois;
+	       nbst = i;
+	   } // end if
+//	   printf("Svertex: bin=%d signal/noise=%e\n",i,(sig-nois)/nois);
+       } // end for i
+   } // end find best dPhi
+
+   if(nbst<=0) nbst = 1; // must have some data.
+   BDphi = Svzdphi->GetYaxis()->GetBinUpEdge(nbst);
+   TH1D *Svzbst = Svzdphi->ProjectionX("Slow: Best, Z vertecies",0,nbst,"E");
+
+   { // Start Muinuit fitting
+       // initilize Minuit package
+       gH1   = Svzbst; // histogram to be fit
+       gstrt = Svzbst->GetXaxis()->FindBin(
+        Svzdef->GetMean()-2.0*(Svzdef->GetRMS()));//histogram start bin value
+       gend  = Svzbst->GetXaxis()->FindBin(
+        Svzdef->GetMean()+2.0*(Svzdef->GetRMS()));//histogram end   bin value
+       TMinuit *gMinuit = new TMinuit(4); // init Minuit
+       gMinuit->SetFCN(Chi2Gauss);  // chi^2 function with Gaussian
+       Double_t arglist[10];  // Munuit parameter array
+       Int_t ierflg = 0; // Muniut error flag
+       //arglist[0] = 1.;
+       //gMinuit->mnexcm("SET ERR",arglist,1,ierglg);
+       // Set starting values and step size for parameters
+       Double_t vstart[4],step[4];
+       { // find background
+	   Float_t ns   = 0.0;
+	   Int_t jend = Svzbst->GetXaxis()->GetNbins();
+	   for(j=1;j<6;j++) ns += Svzbst->GetBinContent(j);
+	   for(j=jend-6;jGetBinContent(j);
+	   vstart[3] = 0.1*ns;
+       } // end find backgrount
+       vstart[1] = Svzbst->GetMean();
+       vstart[2] = Svzbst->GetRMS();
+       if(vstart[2] == 0.0) vstart[2] = 0.04;
+       vstart[0] = (Svzbst->GetEntries() - (Svzbst->GetNbinsX())*vstart[3])*
+	   vstart[2]/TMath::Sqrt(TMath::Pi());
+       if(vstart[0]<=0.0) vstart[0] = 1.0;
+       for(i=0;i<4;i++) step[i] = 0.05*vstart[i];
+       if(vstart[3] <= 0.0) step[3] = 0.1;
+       step[1] = 0.01; // mean expected at about zero set step my hand
+       gMinuit->mnparm(0,"Const",vstart[0],step[0],0,0,ierflg);
+       gMinuit->mnparm(1,"Mean" ,vstart[1],step[1],0,0,ierflg);
+       gMinuit->mnparm(2,"Sigma",vstart[2],step[2],0,0,ierflg);
+       gMinuit->mnparm(3,"Offst",vstart[3],step[3],0,0,ierflg);
+       // Now ready for minimization step
+       //arglist[0] = 500.; // Maximum number of calls
+       //arglist[1] = 1.;   // Tolorance
+       gMinuit->mnexcm("MIGRAD",arglist,0,ierflg); // do minimization
+       gMinuit->mnexcm("MINO",arglist,0,ierflg);   // find best errors
+       // Get results
+       Double_t parmin,edm,errdef;
+       Int_t nvpar,nparx,icstat;
+       gMinuit->mnstat(parmin,edm,errdef,nvpar,nparx,icstat);
+       printf("Svertex: chi2gauss=%e edist=%e istat=%d dPhi=%e\n",
+	      parmin,edm,icstat,BDphi);
+       TString chnam = TString(10);
+       Double_t par[4],epar[4],empar[4],eppar[4];
+       for(i=0;i<4;i++){ 
+	   gMinuit->mnpout(i,chnam,par[i],epar[i],empar[i],eppar[i],ierflg);
+	   gMinuit->mnerrs(i,eppar[i],empar[i],epar[i],arglist[i]);
+	   printf("Svertex: %s = %e +- %e (%e,%e)\n",
+		  chnam.Data(),par[i],epar[i],empar[i],eppar[i]);
+       } // end for i
+   } // End Muinuit fitting
+   su  = 0.0;
+   avt = 0.0;
+   i1  = Svzfl->GetBinContent(1);
+   i2  = Svzfl->GetBinContent(2);
+   for(i=2;iGetBinContent(i+1); // new i+1 value
+       if(i1 > av && (i0 > av || i2 > av ) ){
+	   if(!mod) mod = kTRUE;
+       } else if(mod) break;
+       if(mod){ // inside peak
+	   su  += i1;
+	   avt += i1 * Svzfl->GetXaxis()->GetBinCenter(i);
+       } // end if mod
+   } // end for i
+
+   if(su!=0.0) zv = avt/su;
+   else        zv = -100.0; // an unphysical value
+
+   TCanvas *c1 = new TCanvas("c1","Slow Alice ITS vertex finder",
+        	             450,10,600,700);
+   Svzphi->Draw("col");
+   c1->Print("vertex5_S_vz_phi.eps");
+   Svzdphi->Draw();
+   c1->Print("vertex5_S_vz_dphi.eps");
+   Svzdef->Draw();
+   c1->Print("vertex5_S_vz_def.eps");
+   Svzbst->Draw();
+   c1->Print("vertex5_S_vz_bst.eps");
+   Svztr->Draw();
+   c1->Print("vertex5_S_vz_true.eps");
+
+   return zv;
+}
+
+Float_t vertexEta(Hit_tl **spdi,Int_t i1max,Hit_tl **spdo,Int_t i2max){
+   Float_t r1    = 3.910078;// radius at which hit is from beam axis for spd1
+   Float_t r2    = 6.955933;// radius at which hit is from beam axis for spd2
+   Float_t DPhi  = 0.005;   // maximum allowed difference in phi angle
+   Float_t DEta  = 0.100;   // maximum allowed difference in eta/pseudorapidity
+   Float_t DZ    = 12.5;     // maximum allowed difference in z position
+   Float_t avt   = 0.0;
+   Int_t   nbinx = 2000;
+   Int_t   start = 0;
+   Bool_t  mod   = kFALSE;
+   Int_t   i,j;
+   Float_t zv=0.0,av,su,i0,i1,i2,x0,x1,dphi,dz;
+   Float_t PI2 = 2.0*TMath::Pi();
+   Float_t PI  = TMath::Pi();
+
+   // sort according to phi.
+   hpsortEta(spdi,i1max);
+   hpsortEta(spdo,i2max);
+
+   // find best vertex allong z.
+   TH2S *Evzphi   = new TH2S("Evzphi","Eta: Posible Z vertecies vs. Phi",
+			     nbinx,-5.0,5.0,32,0.0,PI2);
+   Evzphi->Sumw2(); // collect good statitics
+   TH2S *Evzdphi  = new TH2S("Evzdphi","Eta: Posible Z vertecies vs. DPhi",
+			     200,-1.0,1.0,20,0.0,10*DPhi);
+   Evzdphi->Sumw2(); // collect good statitics
+   TH1F *Evzfl   = new TH1F("Evzfl","Eta: Posible Z vertecies Flattened",
+			  nbinx,-5.0,5.0);
+   Evzfl->Sumw2();
+   TH1F *Evztr  = new TH1F("Evztr","Eta: Z Vertex found by True Tracks",
+			   nbinx,-5.0,5.0);
+   Evztr->Sumw2(); // collect good statitics
+
+   for(i=0;ietar < spdi[i]->etar-1.5*DEta;start++);
+       for(j=start;(spdo[j]->etar < spdi[i]->etar+DEta) && (j < i2max);j++){
+	   dphi = fabs(spdi[i]->phir - spdo[j]->phir); if(dphi>PI) dphi -= PI;
+	   dz   = fabs(spdi[i]->zr   - spdo[j]->zr);
+	   r1   = spdi[i]->r;
+	   r2   = spdo[j]->r;
+	   if(r2-r1!=0.0) zv   = (r2*spdi[i]->zr - r1*spdo[j]->zr)/(r2-r1);
+	   else printf("vertex_Eta: spdi[%d]->r=%f = spdo[%d]->r=%f\n",
+		       i,r1,j,r2);
+	   Evzdphi->Fill(zv,dphi);
+	   if(dphi>DPhi) continue;
+	   if(dz>DZ)     continue;
+	   Evzphi->Fill(zv,spdi[i]->phir);
+	   Evzfl->Fill(zv);
+	   if(spdi[i]->track == spdo[j]->track) Evztr ->Fill(zv);
+       } // end for j
+   } // end for i
+
+   TH1D *Evzdef  = Evzphi->ProjectionX("Eta: Z vertecies Eta",1,nbinx,"E");
+
+   i0 = Evzfl->GetBinContent(1);
+   x0 = Float_t(1);
+   i1 = Evzfl->GetBinContent(nbinx);
+   x1 = Float_t(nbinx);
+   su = x0-x1; if(su==0.0) return -200.0;
+   su = (i0-i1)/su;
+   x0 = x0-su*i0;
+   x1 = su;
+   for(i=1;i<=nbinx;i++){
+      su = x1*Float_t(i) + x0;
+      Evzfl->AddBinContent(i,-su);
+   } // end for i
+
+   printf("Eta:           mean=%f RMS=%f w2=%f\n",
+	  Evzdef->GetMean(),Evzdef->GetRMS(),Evzdef->GetSumOfWeights());
+   printf("Eta: Flattened mean=%f RMS=%f w2=%f\n",
+	  Evzfl->GetMean(),Evzfl->GetRMS(),Evzfl->GetSumOfWeights());
+
+   av = 3.0 * Evzfl->Integral(1,nbinx)/Float_t(nbinx);
+   printf("Eta: Flattened av=%f TvxpE->Max=%f nbinx=%d\n",
+	  av,Evzfl->GetMaximum(),nbinx);
+
+   su  = 0.0;
+   avt = 0.0;
+   i1  = Evzfl->GetBinContent(1);
+   i2  = Evzfl->GetBinContent(2);
+   for(i=2;iGetBinContent(i+1); // new i+1 value
+       if(i1 > av && (i0 > av || i2 > av ) ){
+	   if(!mod) mod = kTRUE;
+       } else if(mod) break;
+       if(mod){ // inside peak
+	   su  += i1;
+	   avt += i1 * Evzfl->GetXaxis()->GetBinCenter(i);
+       } // end if mod
+   } // end for i
+
+   if(su!=0.0) zv = avt/su;
+   else        zv = -100.0; // an unphysical value
+
+   TCanvas *c2 = new TCanvas("c2","Alice ITS vertex finder Eta", 
+			     500,10,600,700);
+   Evzphi->Draw("col");
+   c2->Print("vertex5_E_vz_phi.ps");
+   Evzdphi->Draw();
+   c2->Print("vertex5_E_vz_dphi.ps");
+   Evzdef->Draw();
+   c2->Print("vertex5_E_vz_def.ps");
+   Evzfl->Draw();
+   c2->Print("vertex5_E_vz_flat.ps");
+   Evztr->Draw();
+   c2->Print("vertex5_E_vz_true.ps");
+
+   return zv;
+}
diff --git a/ITS/vertex.h b/ITS/vertex.h
new file mode 100755
index 00000000000..a562f6df019
--- /dev/null
+++ b/ITS/vertex.h
@@ -0,0 +1,19 @@
+#ifndef VERTEX_H
+#define VERTEX_H
+struct Hit_tl {
+   Int_t   track,n,lad,det;
+   Float_t x,y,z,xl,yl,zl,xr,yr,zr;
+   Float_t r,phi,eta,phir,etar;
+};
+
+void FindVertexs(Int_t evnt,Float_t frac,Float_t len);
+
+void HitsToV(Hit_tl **spdi,Int_t &nspdi,Hit_tl **spdo,Int_t &nspdo,
+	     Int_t ntracks,TTree *TH,TClonesArray *ITShits,
+	     Float_t fraction,Float_t len);
+
+Float_t vertex(Hit_tl **spdi,Int_t i1max,Hit_tl **spdo,Int_t i2max);
+Float_t vertexSlow(Hit_tl **spdi,Int_t i1max,Hit_tl **spdo,Int_t i2max);
+Float_t vertexEta(Hit_tl **spdi,Int_t i1max,Hit_tl **spdo,Int_t i2max);
+
+#endif
diff --git a/ITS/vertexmacro.C b/ITS/vertexmacro.C
new file mode 100755
index 00000000000..8960f1d377d
--- /dev/null
+++ b/ITS/vertexmacro.C
@@ -0,0 +1,45 @@
+void vertexmacro (const char *filename="galice.root",Int_t evNumber=0) {
+/////////////////////////////////////////////////////////////////////////
+//   This macro is a small example of a ROOT macro
+//   illustrating how to read the output of GALICE
+//   and fill some histograms.
+//   
+//     Root > .L vertexmacro.C   //this loads the macro in memory
+//     Root > vertexmacro();     //by default process first event   
+//     Root > vertexmacro("galice.root");   //process file galice.root
+//     Root > vertexmacro("galice.root",0); // process first event 
+//                                             from galice.root file
+/////////////////////////////////////////////////////////////////////////
+
+
+// Dynamically link some shared libs
+   if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->LoadMacro("loadlibs.C");
+      loadlibs();
+   } // end if gClassTable...
+
+      
+// Connect the Root Galice file containing Geometry, Kine and Hits
+   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+   if (!file){ file = new TFile(filename);printf("Opening new file\n");}
+   printf("Root input file is %s\n",filename);
+
+// Get AliRun object from file or create it if not on file
+   if (!gAlice) {
+      gAlice = (AliRun*)file->Get("gAlice");
+      if (gAlice) printf("AliRun object found on file\n");
+      if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+   }
+//
+
+   for(Int_t evnt=0;evnt<=evNumber;evnt++){
+
+      // define some variables for later use.
+      Int_t      nparticles = gAlice->GetEvent(evnt);
+      if (nparticles <= 0) continue; // get next event
+
+      FindVertexs(evnt,1.0,16.82);
+
+   } // end for evnt
+   return;
+}
-- 
2.39.3