]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RICH/AliRICH.cxx
Corrected invertes arguments in pad size setter
[u/mrichter/AliRoot.git] / RICH / AliRICH.cxx
index 1184ac732fa09b9deeffddb3c1967490d2a1db9e..b4e32b7c5cbb8972b8fd925ccd39d532d96d5a5e 100644 (file)
 
 /*
   $Log$
+  Revision 1.37  2000/12/20 14:07:25  jbarbosa
+  Removed dependencies on TGeant3 (thanks to F. Carminati and I. Hrivnacova)
+
+  Revision 1.36  2000/12/18 17:45:54  jbarbosa
+  Cleaned up PadHits object.
+
+  Revision 1.35  2000/12/15 16:49:40  jbarbosa
+  Geometry and materials updates (wire supports, pcbs, backplane supports, frame).
+
+  Revision 1.34  2000/11/10 18:12:12  jbarbosa
+  Bug fix for AliRICHCerenkov (thanks to P. Hristov)
+
+  Revision 1.33  2000/11/02 10:09:01  jbarbosa
+  Minor bug correction (some pointers were not initialised in the default constructor)
+
+  Revision 1.32  2000/11/01 15:32:55  jbarbosa
+  Updated to handle both reconstruction algorithms.
+
+  Revision 1.31  2000/10/26 20:18:33  jbarbosa
+  Supports for methane and freon vessels
+
+  Revision 1.30  2000/10/24 13:19:12  jbarbosa
+  Geometry updates.
+
+  Revision 1.29  2000/10/19 19:39:25  jbarbosa
+  Some more changes to geometry. Further correction of digitisation "per part. type"
+
+  Revision 1.28  2000/10/17 20:50:57  jbarbosa
+  Inversed digtise by particle type (now, only the selected particle type is not digitsed).
+  Corrected several geometry minor bugs.
+  Added new parameter (opaque quartz thickness).
+
+  Revision 1.27  2000/10/11 10:33:55  jbarbosa
+  Corrected bug introduced by earlier revisions  (CerenkovData array cannot be reset to zero on wach call of StepManager)
+
+  Revision 1.26  2000/10/03 21:44:08  morsch
+  Use AliSegmentation and AliHit abstract base classes.
+
+  Revision 1.25  2000/10/02 21:28:12  fca
+  Removal of useless dependecies via forward declarations
+
+  Revision 1.24  2000/10/02 15:43:17  jbarbosa
+  Fixed forward declarations.
+  Fixed honeycomb density.
+  Fixed cerenkov storing.
+  New electronics.
+
   Revision 1.23  2000/09/13 10:42:14  hristov
   Minor corrections for HP, DEC and Sun; strings.h included
 
 #include <TArrayF.h>
 #include <TFile.h>
 #include <TParticle.h>
+#include <TGeometry.h>
+#include <TTree.h>
+
 #include <iostream.h>
 #include <strings.h>
 
 #include "AliRICH.h"
-#include "AliRICHSegmentation.h"
+#include "AliSegmentation.h"
 #include "AliRICHHit.h"
 #include "AliRICHCerenkov.h"
 #include "AliRICHPadHit.h"
 #include "AliRICHDigit.h"
 #include "AliRICHTransientDigit.h"
 #include "AliRICHRawCluster.h"
-#include "AliRICHRecHit.h"
+#include "AliRICHRecHit1D.h"
+#include "AliRICHRecHit3D.h"
 #include "AliRICHHitMapA1.h"
 #include "AliRICHClusterFinder.h"
 #include "AliRun.h"
 #include "AliMC.h"
+#include "AliMagF.h"
 #include "AliConst.h"
 #include "AliPDG.h"
 #include "AliPoints.h"
 #include "AliCallf77.h" 
-#include "TGeant3.h"
 
 
 // Static variables for the pad-hit iterator routines
@@ -99,13 +150,20 @@ AliRICH::AliRICH()
     fNPadHits   = 0;
     fNcerenkovs = 0;
     fDchambers  = 0;
+    fRecHits1D = 0;
+    fRecHits3D = 0;
+    fRawClusters = 0;
+    fChambers = 0;
     fCerenkovs  = 0;
     for (Int_t i=0; i<7; i++)
       {
        fNdch[i]       = 0;
        fNrawch[i]   = 0;
-       fNrechits[i] = 0;
+       fNrechits1D[i] = 0;
+       fNrechits3D[i] = 0;
       }
+
+    fFileName = 0;
 }
 
 //___________________________________________
@@ -132,7 +190,8 @@ AliRICH::AliRICH(const char *name, const char *title)
     
     fDchambers = new TObjArray(kNCH);
 
-    fRecHits = new TObjArray(kNCH);
+    fRecHits1D = new TObjArray(kNCH);
+    fRecHits3D = new TObjArray(kNCH);
     
     Int_t i;
    
@@ -154,12 +213,22 @@ AliRICH::AliRICH(const char *name, const char *title)
     //fNrechits      = new Int_t[kNCH];
     
     for (i=0; i<kNCH ;i++) {
-       (*fRecHits)[i] = new TClonesArray("AliRICHRecHit",1000); 
+      (*fRecHits1D)[i] = new TClonesArray("AliRICHRecHit1D",1000);
+    }
+    for (i=0; i<kNCH ;i++) {
+      (*fRecHits3D)[i] = new TClonesArray("AliRICHRecHit3D",1000);     
     }
     //printf("Created fRecHits with adress:%p",fRecHits);
 
         
     SetMarkerColor(kRed);
+    
+    /*fChambers = new TObjArray(kNCH);
+    for (i=0; i<kNCH; i++) 
+      (*fChambers)[i] = new AliRICHChamber();*/  
+    
+    fFileName = 0;
+
 }
 
 AliRICH::AliRICH(const AliRICH& RICH)
@@ -178,6 +247,29 @@ AliRICH::~AliRICH()
     delete fHits;
     delete fPadHits;
     delete fCerenkovs;
+    
+    //PH Delete TObjArrays
+    if (fChambers) {
+      fChambers->Delete();
+      delete fChambers;
+    }
+    if (fDchambers) {
+      fDchambers->Delete();
+      delete fDchambers;
+    }
+    if (fRawClusters) {
+      fRawClusters->Delete();
+      delete fRawClusters;
+    }
+    if (fRecHits1D) {
+      fRecHits1D->Delete();
+      delete fRecHits1D;
+    }
+    if (fRecHits3D) {
+      fRecHits3D->Delete();
+      delete fRecHits3D;
+    }                     
+    
 }
 
 //___________________________________________
@@ -238,15 +330,27 @@ void AliRICH::AddRawCluster(Int_t id, const AliRICHRawCluster& c)
 }
 
 //_____________________________________________________________________________
-void AliRICH::AddRecHit(Int_t id, Float_t *rechit, Float_t *photons, Int_t *padsx, Int_t* padsy)
+void AliRICH::AddRecHit1D(Int_t id, Float_t *rechit, Float_t *photons, Int_t *padsx, Int_t* padsy)
 {
   
   //
   // Add a RICH reconstructed hit to the list
   //
 
-    TClonesArray &lrec = *((TClonesArray*)(*fRecHits)[id]);
-    new(lrec[fNrechits[id]++]) AliRICHRecHit(id,rechit,photons,padsx,padsy);
+    TClonesArray &lrec1D = *((TClonesArray*)(*fRecHits1D)[id]);
+    new(lrec1D[fNrechits1D[id]++]) AliRICHRecHit1D(id,rechit,photons,padsx,padsy);
+}
+
+//_____________________________________________________________________________
+void AliRICH::AddRecHit3D(Int_t id, Float_t *rechit)
+{
+  
+  //
+  // Add a RICH reconstructed hit to the list
+  //
+
+    TClonesArray &lrec3D = *((TClonesArray*)(*fRecHits3D)[id]);
+    new(lrec3D[fNrechits3D[id]++]) AliRICHRecHit3D(id,rechit);
 }
 
 //___________________________________________
@@ -352,7 +456,7 @@ void AliRICH::CreateGeometry()
     //End_Html
 
   AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH"); 
-  AliRICHSegmentation*  segmentation;
+  AliSegmentation*  segmentation;
   AliRICHGeometry*  geometry;
   AliRICHChamber*       iChamber;
 
@@ -364,6 +468,12 @@ void AliRICH::CreateGeometry()
   distance = geometry->GetFreonThickness()/2 + geometry->GetQuartzThickness() + geometry->GetGapThickness();
   geometry->SetRadiatorToPads(distance);
     
+  //Opaque quartz thickness
+  Float_t oqua_thickness = .5;
+  //CsI dimensions
+
+  Float_t csi_length = 160*.8 + 2.6;
+  Float_t csi_width = 144*.84 + 2*2.6;
     
     Int_t *idtmed = fIdtmed->GetArray()-999;
     
@@ -374,36 +484,50 @@ void AliRICH::CreateGeometry()
     
     // --- Define the RICH detector 
     //     External aluminium box 
-    par[0] = 71.1;
-    par[1] = 11.5;                 //Original Settings
-    par[2] = 73.15;
+    par[0] = 68.8;
+    par[1] = 13;                 //Original Settings
+    par[2] = 70.86;
     /*par[0] = 73.15;
     par[1] = 11.5;
     par[2] = 71.1;*/
     gMC->Gsvolu("RICH", "BOX ", idtmed[1009], par, 3);
     
-    //     Sensitive part of the whole RICH 
-    par[0] = 64.8;
-    par[1] = 11.5;                 //Original Settings
-    par[2] = 66.55;
+    //     Air 
+    par[0] = 66.3;
+    par[1] = 13;                 //Original Settings
+    par[2] = 68.35;
     /*par[0] = 66.55;
     par[1] = 11.5;
     par[2] = 64.8;*/
     gMC->Gsvolu("SRIC", "BOX ", idtmed[1000], par, 3);
     
+    //    Air 2 (cutting the lower part of the box)
+    
+    par[0] = 1.25;
+    par[1] = 3;                 //Original Settings
+    par[2] = 70.86;
+    gMC->Gsvolu("AIR2", "BOX ", idtmed[1000], par, 3);
+
+    //    Air 3 (cutting the lower part of the box)
+    
+    par[0] = 66.3;
+    par[1] = 3;                 //Original Settings
+    par[2] = 1.2505;
+    gMC->Gsvolu("AIR3", "BOX ", idtmed[1000], par, 3);
+    
     //     Honeycomb 
-    par[0] = 63.1;
+    par[0] = 66.3;
     par[1] = .188;                 //Original Settings
-    par[2] = 66.55;
+    par[2] = 68.35;
     /*par[0] = 66.55;
     par[1] = .188;
     par[2] = 63.1;*/
     gMC->Gsvolu("HONE", "BOX ", idtmed[1001], par, 3);
     
     //     Aluminium sheet 
-    par[0] = 63.1;
+    par[0] = 66.3;
     par[1] = .025;                 //Original Settings
-    par[2] = 66.55;
+    par[2] = 68.35;
     /*par[0] = 66.5;
     par[1] = .025;
     par[2] = 63.1;*/
@@ -428,10 +552,20 @@ void AliRICH::CreateGeometry()
     par[2] = geometry->GetFreonThickness()/2;
     gMC->Gsvolu("SPAC", "TUBE", idtmed[1002], par, 3);
     
+    //     Feet (freon slabs supports)
+
+    par[0] = .7;
+    par[1] = .3;
+    par[2] = 1.9;
+    gMC->Gsvolu("FOOT", "BOX", idtmed[1009], par, 3);
+
     //     Opaque quartz 
-    par[0] = 61.95;
+    par[0] = geometry->GetQuartzWidth()/2;
+    par[1] = .2;
+    par[2] = geometry->GetQuartzLength()/2;
+    /*par[0] = 61.95;
     par[1] = .2;                   //Original Settings
-    par[2] = 66.5;
+    par[2] = 66.5;*/
     /*par[0] = 66.5;
     par[1] = .2;
     par[2] = 61.95;*/
@@ -439,8 +573,10 @@ void AliRICH::CreateGeometry()
   
     //     Frame of opaque quartz
     par[0] = geometry->GetOuterFreonWidth()/2;
+    //+ oqua_thickness;
     par[1] = geometry->GetFreonThickness()/2;
-    par[2] = geometry->GetOuterFreonLength()/2 + 1; 
+    par[2] = geometry->GetOuterFreonLength()/2; 
+    //+ oqua_thickness; 
     /*par[0] = 20.65;
     par[1] = .5;                   //Original Settings
     par[2] = 66.5;*/
@@ -451,25 +587,27 @@ void AliRICH::CreateGeometry()
 
     par[0] = geometry->GetInnerFreonWidth()/2;
     par[1] = geometry->GetFreonThickness()/2;
-    par[2] = geometry->GetInnerFreonLength()/2 + 1
+    par[2] = geometry->GetInnerFreonLength()/2; 
     gMC->Gsvolu("OQF2", "BOX ", idtmed[1007], par, 3);
     
     //     Little bar of opaque quartz 
-    par[0] = .275;
-    par[1] = geometry->GetQuartzThickness()/2;
-    par[2] = geometry->GetInnerFreonLength()/2 - 2.4; 
+    //par[0] = .275;
+    //par[1] = geometry->GetQuartzThickness()/2;
+    //par[2] = geometry->GetInnerFreonLength()/2 - 2.4; 
+    //par[2] = geometry->GetInnerFreonLength()/2;
+    //+ oqua_thickness;
     /*par[0] = .275;
     par[1] = .25;                   //Original Settings
     par[2] = 63.1;*/
     /*par[0] = 63.1;
     par[1] = .25;
     par[2] = .275;*/
-    gMC->Gsvolu("BARR", "BOX ", idtmed[1007], par, 3);
+    //gMC->Gsvolu("BARR", "BOX ", idtmed[1007], par, 3);
     
     //     Freon 
-    par[0] = geometry->GetOuterFreonWidth()/2;
+    par[0] = geometry->GetOuterFreonWidth()/2 - oqua_thickness;
     par[1] = geometry->GetFreonThickness()/2;
-    par[2] = geometry->GetOuterFreonLength()/2; 
+    par[2] = geometry->GetOuterFreonLength()/2 - 2*oqua_thickness
     /*par[0] = 20.15;
     par[1] = .5;                   //Original Settings
     par[2] = 65.5;*/
@@ -478,29 +616,35 @@ void AliRICH::CreateGeometry()
     par[2] = 20.15;*/
     gMC->Gsvolu("FRE1", "BOX ", idtmed[1003], par, 3);
 
-    par[0] = geometry->GetInnerFreonWidth()/2;
+    par[0] = geometry->GetInnerFreonWidth()/2 - oqua_thickness;
     par[1] = geometry->GetFreonThickness()/2;
-    par[2] = geometry->GetInnerFreonLength()/2; 
+    par[2] = geometry->GetInnerFreonLength()/2 - 2*oqua_thickness
     gMC->Gsvolu("FRE2", "BOX ", idtmed[1003], par, 3);
     
     //     Methane 
-    par[0] = 64.8;
+    //par[0] = 64.8;
+    par[0] = csi_width/2;
     par[1] = geometry->GetGapThickness()/2;
     //printf("\n\n\n\n\n\n\n\\n\n\n\n Gap Thickness: %f\n\n\n\n\n\n\n\n\n\n\n\n\n\n",par[1]);
-    par[2] = 64.8;
+    //par[2] = 64.8;
+    par[2] = csi_length/2;
     gMC->Gsvolu("META", "BOX ", idtmed[1004], par, 3);
     
     //     Methane gap 
-    par[0] = 64.8;
+    //par[0] = 64.8;
+    par[0] = csi_width/2;
     par[1] = geometry->GetProximityGapThickness()/2;
     //printf("\n\n\n\n\n\n\n\\n\n\n\n Gap Thickness: %f\n\n\n\n\n\n\n\n\n\n\n\n\n\n",par[1]);
-    par[2] = 64.8;
+    //par[2] = 64.8;
+    par[2] = csi_length/2;
     gMC->Gsvolu("GAP ", "BOX ", idtmed[1008], par, 3);
     
     //     CsI photocathode 
-    par[0] = 64.8;
+    //par[0] = 64.8;
+    par[0] = csi_width/2;
     par[1] = .25;
-    par[2] = 64.8;
+    //par[2] = 64.8;
+    par[2] = csi_length/2;
     gMC->Gsvolu("CSI ", "BOX ", idtmed[1005], par, 3);
     
     //     Anode grid 
@@ -508,19 +652,154 @@ void AliRICH::CreateGeometry()
     par[1] = .001;
     par[2] = 20.;
     gMC->Gsvolu("GRID", "TUBE", idtmed[1006], par, 3);
+
+    // Wire supports
+    // Bar of metal
+    
+    par[0] = csi_width/2;
+    par[1] = 1.05;
+    par[2] = 1.05;
+    gMC->Gsvolu("WSMe", "BOX ", idtmed[1009], par, 3);
+
+    // Ceramic pick up (base)
     
+    par[0] =  csi_width/2;
+    par[1] = .25;
+    par[2] = 1.05;
+    gMC->Gsvolu("WSG1", "BOX ", idtmed[1010], par, 3);
+
+    // Ceramic pick up (head)
+
+    par[0] = csi_width/2;
+    par[1] = .1;
+    par[2] = .1;
+    gMC->Gsvolu("WSG2", "BOX ", idtmed[1010], par, 3);
+
+    // Aluminium supports for methane and CsI
+    // Short bar
+
+    par[0] = csi_width/2;
+    par[1] = geometry->GetGapThickness()/2 + .25;
+    par[2] = (68.35 - csi_length/2)/2;
+    gMC->Gsvolu("SMSH", "BOX", idtmed[1009], par, 3);
+    
+    // Long bar
+
+    par[0] = (66.3 - csi_width/2)/2;
+    par[1] = geometry->GetGapThickness()/2 + .25;
+    par[2] = csi_length/2 + 68.35 - csi_length/2;
+    gMC->Gsvolu("SMLG", "BOX", idtmed[1009], par, 3);
+    
+    // Aluminium supports for freon
+    // Short bar
+
+    par[0] = geometry->GetQuartzWidth()/2;
+    par[1] = .3;
+    par[2] = (68.35 - geometry->GetQuartzLength()/2)/2;
+    gMC->Gsvolu("SFSH", "BOX", idtmed[1009], par, 3);
+    
+    // Long bar
+
+    par[0] = (66.3 - geometry->GetQuartzWidth()/2)/2;
+    par[1] = .3;
+    par[2] = geometry->GetQuartzLength()/2 + 68.35 - geometry->GetQuartzLength()/2;
+    gMC->Gsvolu("SFLG", "BOX", idtmed[1009], par, 3);
+    
+    // PCB backplane
+    
+    par[0] = csi_width/2;
+    par[1] = .25;
+    par[2] = csi_length/4 -.5025;
+    gMC->Gsvolu("PCB ", "BOX", idtmed[1011], par, 3);
+
+    
+    // Backplane supports
+
+    // Aluminium slab
+    
+    par[0] = 33.15;
+    par[1] = 2;
+    par[2] = 21.65;
+    gMC->Gsvolu("BACK", "BOX", idtmed[1009], par, 3);
+    
+    // Big hole
+    
+    par[0] = 9.05;
+    par[1] = 2;
+    par[2] = 4.4625;
+    gMC->Gsvolu("BKHL", "BOX", idtmed[1000], par, 3);
+
+    // Small hole
+    
+    par[0] = 5.7;
+    par[1] = 2;
+    par[2] = 4.4625;
+    gMC->Gsvolu("BKHS", "BOX", idtmed[1000], par, 3);
+
+    // Place holes inside backplane support
+
+    gMC->Gspos("BKHS", 1, "BACK", .8 + 5.7,0., .6 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHS", 2, "BACK", -.8 - 5.7,0., .6 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHS", 3, "BACK", .8 + 5.7,0., -.6 - 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHS", 4, "BACK", -.8 - 5.7,0., -.6 - 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHS", 5, "BACK", .8 + 5.7,0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHS", 6, "BACK", -.8 - 5.7,0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHS", 7, "BACK", .8 + 5.7,0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHS", 8, "BACK", -.8 - 5.7,0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 1, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., .6 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 2, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., .6 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 3, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., -.6 - 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 4, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., -.6 - 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 5, "BACK", .8 + 11.4+ 1.6 + 9.05, 0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 6, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 7, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
+    gMC->Gspos("BKHL", 8, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
+
+    
+  
     // --- Places the detectors defined with GSVOLU 
     //     Place material inside RICH 
-    gMC->Gspos("SRIC", 1, "RICH", 0., 0., 0., 0, "ONLY");
+    gMC->Gspos("SRIC", 1, "RICH", 0.,0., 0., 0, "ONLY");
+    gMC->Gspos("AIR2", 1, "RICH", 66.3 + 1.2505, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.5, 0., 0, "ONLY");
+    gMC->Gspos("AIR2", 2, "RICH", -66.3 - 1.2505, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.5, 0., 0, "ONLY");
+    gMC->Gspos("AIR3", 1, "RICH", 0.,  1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.5, -68.35 - 1.25, 0, "ONLY");
+    gMC->Gspos("AIR3", 2, "RICH", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.5,  68.35 + 1.25, 0, "ONLY");
     
-    gMC->Gspos("ALUM", 1, "SRIC", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 -.05 - .376 -.025, 0., 0, "ONLY");
-    gMC->Gspos("HONE", 1, "SRIC", 0., 1.276- geometry->GetGapThickness()/2  - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 -.05 - .188, 0., 0, "ONLY");
-    gMC->Gspos("ALUM", 2, "SRIC", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .025, 0., 0, "ONLY");
+      
+    gMC->Gspos("ALUM", 1, "SRIC", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .6 - .05 - .376 -.025, 0., 0, "ONLY");
+    gMC->Gspos("HONE", 1, "SRIC", 0., 1.276- geometry->GetGapThickness()/2  - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .6 - .05 - .188, 0., 0, "ONLY");
+    gMC->Gspos("ALUM", 2, "SRIC", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .6 - .025, 0., 0, "ONLY");
+    gMC->Gspos("FOOT", 1, "SRIC", 64.95, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3, 36.9, 0, "ONLY");
+    gMC->Gspos("FOOT", 2, "SRIC", 21.65, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3 , 36.9, 0, "ONLY");
+    gMC->Gspos("FOOT", 3, "SRIC", -21.65, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3, 36.9, 0, "ONLY");
+    gMC->Gspos("FOOT", 4, "SRIC", -64.95, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3, 36.9, 0, "ONLY");
+    gMC->Gspos("FOOT", 5, "SRIC", 64.95, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3, -36.9, 0, "ONLY");
+    gMC->Gspos("FOOT", 6, "SRIC", 21.65, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3, -36.9, 0, "ONLY");
+    gMC->Gspos("FOOT", 7, "SRIC", -21.65, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3, -36.9, 0, "ONLY");
+    gMC->Gspos("FOOT", 8, "SRIC", -64.95, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .4 - .3, -36.9, 0, "ONLY");
     gMC->Gspos("OQUA", 1, "SRIC", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()- .2, 0., 0, "ONLY");
     
+    // Supports placing
+
+    // Methane supports
+    gMC->Gspos("SMLG", 1, "SRIC", csi_width/2 + (66.3 - csi_width/2)/2, 1.276 + .25, 0., 0, "ONLY");
+    gMC->Gspos("SMLG", 2, "SRIC", - csi_width/2 - (66.3 - csi_width/2)/2, 1.276 + .25, 0., 0, "ONLY");
+    gMC->Gspos("SMSH", 1, "SRIC", 0., 1.276 + .25, csi_length/2 + (68.35 - csi_length/2)/2, 0, "ONLY");
+    gMC->Gspos("SMSH", 2, "SRIC", 0., 1.276 + .25, - csi_length/2 - (68.35 - csi_length/2)/2, 0, "ONLY");
+
+    //Freon supports
+
+    Float_t supp_y = 1.276 - geometry->GetGapThickness()/2- geometry->GetQuartzThickness() -geometry->GetFreonThickness() - .2 + .3; //y position of freon supports
+
+    gMC->Gspos("SFLG", 1, "SRIC", geometry->GetQuartzWidth()/2 + (66.3 - geometry->GetQuartzWidth()/2)/2, supp_y, 0., 0, "ONLY");
+    gMC->Gspos("SFLG", 2, "SRIC", - geometry->GetQuartzWidth()/2 - (66.3 - geometry->GetQuartzWidth()/2)/2, supp_y, 0., 0, "ONLY");
+    gMC->Gspos("SFSH", 1, "SRIC", 0., supp_y, geometry->GetQuartzLength()/2 + (68.35 - geometry->GetQuartzLength()/2)/2, 0, "ONLY");
+    gMC->Gspos("SFSH", 2, "SRIC", 0., supp_y, - geometry->GetQuartzLength()/2 - (68.35 - geometry->GetQuartzLength()/2)/2, 0, "ONLY");
+    
     AliMatrix(idrotm[1019], 0., 0., 90., 0., 90., 90.);
     
-    Int_t nspacers = (Int_t)(TMath::Abs(geometry->GetInnerFreonLength()/14.4));
+    //Int_t nspacers = (Int_t)(TMath::Abs(geometry->GetInnerFreonLength()/14.4));
+    Int_t nspacers = 9;
     //printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n Spacers:%d\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",nspacers); 
 
     //printf("Nspacers: %d", nspacers);
@@ -570,15 +849,37 @@ void AliRICH::CreateGeometry()
 
     gMC->Gspos("FRE1", 1, "OQF1", 0., 0., 0., 0, "ONLY");
     gMC->Gspos("FRE2", 1, "OQF2", 0., 0., 0., 0, "ONLY");
-    gMC->Gspos("OQF1", 1, "SRIC", geometry->GetOuterFreonWidth()/2 + geometry->GetInnerFreonWidth()/2, 1.276 - geometry->GetGapThickness()/2- geometry->GetQuartzThickness() -geometry->GetFreonThickness()/2, 0., 0, "ONLY"); //Original settings (31.3)
+    gMC->Gspos("OQF1", 1, "SRIC", geometry->GetOuterFreonWidth()/2 + geometry->GetInnerFreonWidth()/2 + 2, 1.276 - geometry->GetGapThickness()/2- geometry->GetQuartzThickness() -geometry->GetFreonThickness()/2, 0., 0, "ONLY"); //Original settings (31.3)
     gMC->Gspos("OQF2", 2, "SRIC", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()/2, 0., 0, "ONLY");          //Original settings 
-    gMC->Gspos("OQF1", 3, "SRIC", - (geometry->GetOuterFreonWidth()/2 + geometry->GetInnerFreonWidth()/2), 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()/2, 0., 0, "ONLY");       //Original settings (-31.3)
-    gMC->Gspos("BARR", 1, "QUAR", -21.65, 0., 0., 0, "ONLY");           //Original settings 
-    gMC->Gspos("BARR", 2, "QUAR", 21.65, 0., 0., 0, "ONLY");            //Original settings 
+    gMC->Gspos("OQF1", 3, "SRIC", - (geometry->GetOuterFreonWidth()/2 + geometry->GetInnerFreonWidth()/2) - 2, 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness() - geometry->GetFreonThickness()/2, 0., 0, "ONLY");       //Original settings (-31.3)
+    //gMC->Gspos("BARR", 1, "QUAR", - geometry->GetInnerFreonWidth()/2 - oqua_thickness, 0., 0., 0, "ONLY");           //Original settings (-21.65) 
+    //gMC->Gspos("BARR", 2, "QUAR",  geometry->GetInnerFreonWidth()/2 + oqua_thickness, 0., 0., 0, "ONLY");            //Original settings (21.65)
     gMC->Gspos("QUAR", 1, "SRIC", 0., 1.276 - geometry->GetGapThickness()/2 - geometry->GetQuartzThickness()/2, 0., 0, "ONLY");
     gMC->Gspos("GAP ", 1, "META", 0., geometry->GetGapThickness()/2 - geometry->GetProximityGapThickness()/2 - 0.0001, 0., 0, "ONLY");
     gMC->Gspos("META", 1, "SRIC", 0., 1.276, 0., 0, "ONLY");
     gMC->Gspos("CSI ", 1, "SRIC", 0., 1.276 + geometry->GetGapThickness()/2 + .25, 0., 0, "ONLY");
+   
+    // Wire support placing
+
+    gMC->Gspos("WSG2", 1, "GAP ", 0., geometry->GetProximityGapThickness()/2 - .1, 0., 0, "ONLY");
+    gMC->Gspos("WSG1", 1, "CSI ", 0., 0., 0., 0, "ONLY");
+    gMC->Gspos("WSMe", 1, "SRIC ", 0., 1.276 + geometry->GetGapThickness()/2 + .5 + 1.05, 0., 0, "ONLY");
+
+    // Backplane placing
+    
+    gMC->Gspos("BACK", 1, "SRIC ", -33.15, 1.276 + geometry->GetGapThickness()/2 + .5 + 2.1 + 2, 43.3, 0, "ONLY");
+    gMC->Gspos("BACK", 2, "SRIC ", 33.15, 1.276 + geometry->GetGapThickness()/2 + .5 + 2.1 + 2 , 43.3, 0, "ONLY");
+    gMC->Gspos("BACK", 3, "SRIC ", -33.15, 1.276 + geometry->GetGapThickness()/2 + .5 + 2.1 + 2, 0., 0, "ONLY");
+    gMC->Gspos("BACK", 4, "SRIC ", 33.15, 1.276 + geometry->GetGapThickness()/2 + .5 + 2.1 + 2, 0., 0, "ONLY");
+    gMC->Gspos("BACK", 5, "SRIC ", 33.15, 1.276 + geometry->GetGapThickness()/2 + .5 + 2.1 + 2, -43.3, 0, "ONLY");
+    gMC->Gspos("BACK", 6, "SRIC ", -33.15, 1.276 + geometry->GetGapThickness()/2 + .5 + 2.1 + 2, -43.3, 0, "ONLY");
+
+    // PCB placing
+    
+    gMC->Gspos("PCB ", 1, "SRIC ", 0.,  1.276 + geometry->GetGapThickness()/2 + .5 + 1.05, csi_width/4 + .5025 + 1.2, 0, "ONLY");
+    gMC->Gspos("PCB ", 2, "SRIC ", 0.,  1.276 + geometry->GetGapThickness()/2 + .5 + 1.05, -csi_width/4 - .5025 - 1.2, 0, "ONLY");
+   
+    
 
     //printf("Position of the gap: %f to %f\n", 1.276 + geometry->GetGapThickness()/2 - geometry->GetProximityGapThickness()/2 - .2, 1.276 + geometry->GetGapThickness()/2 - geometry->GetProximityGapThickness()/2 + .2);
     
@@ -798,8 +1099,6 @@ void AliRICH::CreateMaterials()
     
     Int_t *idtmed = fIdtmed->GetArray()-999;
     
-    TGeant3 *geant3 = (TGeant3*) gMC;
-    
     // --- Photon energy (GeV) 
     // --- Refraction indexes 
     for (i = 0; i < 26; ++i) {
@@ -874,6 +1173,14 @@ void AliRICH::CreateMaterials()
     zal    = 13.;
     densal = 2.7;
     radlal = 8.9;
+
+    // --- Glass parameters
+
+    Float_t aglass[5]={12.01, 28.09, 16.,   10.8,  23.};
+    Float_t zglass[5]={ 6.,   14.,    8.,    5.,   11.};
+    Float_t wglass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
+    Float_t dglass=1.74;
+
     
     AliMaterial(1, "Air     $", 14.61, 7.3, .001205, 30420., 67500);
     AliMaterial(6, "HON", ahon, zhon, denshon, radlhon, 0);
@@ -885,6 +1192,8 @@ void AliRICH::CreateMaterials()
     AliMixture(41, "METG", amet, zmet, densmet, nlmatmet, wmatmet);
     AliMaterial(11, "GRI", agri, zgri, densgri, radlgri, 0);
     AliMaterial(50, "ALUM", aal, zal, densal, radlal, 0);
+    AliMixture(32, "GLASS",aglass, zglass, dglass, 5, wglass);
+    AliMaterial(31, "COPPER$",   63.54,    29.,   8.96,  1.4, 0.);
     
     tmaxfd = -10.;
     stemax = -.1;
@@ -902,18 +1211,21 @@ void AliRICH::CreateMaterials()
     AliMedium(8, "QUARZOO$", 21, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
     AliMedium(9, "GAP$", 41, 1, isxfld, sxmgmx,tmaxfd, .1, -deemax, epsil, -stmin);
     AliMedium(10, "ALUMINUM$", 50, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
-    
-
-    geant3->Gsckov(idtmed[1000], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
-    geant3->Gsckov(idtmed[1001], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
-    geant3->Gsckov(idtmed[1002], 26, ppckov, abscoQuarz, efficAll,rIndexQuarz);
-    geant3->Gsckov(idtmed[1003], 26, ppckov, abscoFreon, efficAll,rIndexFreon);
-    geant3->Gsckov(idtmed[1004], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
-    geant3->Gsckov(idtmed[1005], 26, ppckov, abscoCsI, efficCsI, rIndexMethane);
-    geant3->Gsckov(idtmed[1006], 26, ppckov, abscoGrid, efficGrid, rIndexGrid);
-    geant3->Gsckov(idtmed[1007], 26, ppckov, abscoOpaqueQuarz, efficAll, rIndexOpaqueQuarz);
-    geant3->Gsckov(idtmed[1008], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
-    geant3->Gsckov(idtmed[1009], 26, ppckov, abscoGrid, efficGrid, rIndexGrid);
+    AliMedium(11, "GLASS", 32, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
+    AliMedium(12, "PCB_COPPER", 31, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
+    
+
+    gMC->SetCerenkov(idtmed[1000], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
+    gMC->SetCerenkov(idtmed[1001], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
+    gMC->SetCerenkov(idtmed[1002], 26, ppckov, abscoQuarz, efficAll,rIndexQuarz);
+    gMC->SetCerenkov(idtmed[1003], 26, ppckov, abscoFreon, efficAll,rIndexFreon);
+    gMC->SetCerenkov(idtmed[1004], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
+    gMC->SetCerenkov(idtmed[1005], 26, ppckov, abscoCsI, efficCsI, rIndexMethane);
+    gMC->SetCerenkov(idtmed[1006], 26, ppckov, abscoGrid, efficGrid, rIndexGrid);
+    gMC->SetCerenkov(idtmed[1007], 26, ppckov, abscoOpaqueQuarz, efficAll, rIndexOpaqueQuarz);
+    gMC->SetCerenkov(idtmed[1008], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
+    gMC->SetCerenkov(idtmed[1009], 26, ppckov, abscoGrid, efficGrid, rIndexGrid);
+    gMC->SetCerenkov(idtmed[1010], 26, ppckov, abscoOpaqueQuarz, efficAll, rIndexOpaqueQuarz);
 }
 
 //___________________________________________
@@ -1179,13 +1491,22 @@ void AliRICH::MakeBranch(Option_t* option)
 
   // one branch for rec hits per chamber
   for (i=0; i<kNCH ;i++) {
-    sprintf(branchname,"%sRecHits%d",GetName(),i+1);
+    sprintf(branchname,"%sRecHits1D%d",GetName(),i+1);
     
-    if (fRecHits   && gAlice->TreeR()) {
-      gAlice->TreeR()->Branch(branchname,&((*fRecHits)[i]), kBufferSize);
-      printf("Making Branch %s for rec. hits in chamber %d\n",branchname,i+1);
+    if (fRecHits1D   && gAlice->TreeR()) {
+      gAlice->TreeR()->Branch(branchname,&((*fRecHits1D)[i]), kBufferSize);
+      printf("Making Branch %s for 1D rec. hits in chamber %d\n",branchname,i+1);
     }  
   }
+  for (i=0; i<kNCH ;i++) {
+    sprintf(branchname,"%sRecHits3D%d",GetName(),i+1);
+    
+    if (fRecHits3D   && gAlice->TreeR()) {
+      gAlice->TreeR()->Branch(branchname,&((*fRecHits3D)[i]), kBufferSize);
+      printf("Making Branch %s for 3D rec. hits in chamber %d\n",branchname,i+1);
+    }  
+  }
+  
 }
 
 //___________________________________________
@@ -1232,13 +1553,21 @@ void AliRICH::SetTreeAddress()
       }
       
       for (i=0; i<kNCH; i++) {
-       sprintf(branchname,"%sRecHits%d",GetName(),i+1);
-       if (fRecHits) {
+       sprintf(branchname,"%sRecHits1D%d",GetName(),i+1);
+       if (fRecHits1D) {
          branch = treeR->GetBranch(branchname);
-         if (branch) branch->SetAddress(&((*fRecHits)[i]));
+         if (branch) branch->SetAddress(&((*fRecHits1D)[i]));
          }
       }
       
+     for (i=0; i<kNCH; i++) {
+       sprintf(branchname,"%sRecHits3D%d",GetName(),i+1);
+       if (fRecHits3D) {
+         branch = treeR->GetBranch(branchname);
+         if (branch) branch->SetAddress(&((*fRecHits3D)[i]));
+         }
+      } 
+      
   }
 }
 //___________________________________________
@@ -1278,15 +1607,28 @@ void AliRICH::ResetRawClusters()
 }
 
 //____________________________________________
-void AliRICH::ResetRecHits()
+void AliRICH::ResetRecHits1D()
+{
+  //
+  // Reset number of raw clusters and the raw clust array for this detector
+  //
+  
+  for ( int i=0;i<kNCH;i++ ) {
+       if ((*fRecHits1D)[i])    ((TClonesArray*)(*fRecHits1D)[i])->Clear();
+       if (fNrechits1D)  fNrechits1D[i]=0;
+    }
+}
+
+//____________________________________________
+void AliRICH::ResetRecHits3D()
 {
   //
   // Reset number of raw clusters and the raw clust array for this detector
   //
   
   for ( int i=0;i<kNCH;i++ ) {
-       if ((*fRecHits)[i])    ((TClonesArray*)(*fRecHits)[i])->Clear();
-       if (fNrechits)  fNrechits[i]=0;
+       if ((*fRecHits3D)[i])    ((TClonesArray*)(*fRecHits3D)[i])->Clear();
+       if (fNrechits3D)  fNrechits3D[i]=0;
     }
 }
 
@@ -1303,14 +1645,14 @@ void   AliRICH::SetGeometryModel(Int_t id, AliRICHGeometry *geometry)
 }
 
 //___________________________________________
-void   AliRICH::SetSegmentationModel(Int_t id, AliRICHSegmentation *segmentation)
+void   AliRICH::SetSegmentationModel(Int_t id, AliSegmentation *segmentation)
 {
 
 //
 // Setter for the RICH segmentation model
 //
 
-    ((AliRICHChamber*) (*fChambers)[id])->SegmentationModel(segmentation);
+    ((AliRICHChamber*) (*fChambers)[id])->SetSegmentationModel(segmentation);
 }
 
 //___________________________________________
@@ -1331,7 +1673,7 @@ void   AliRICH::SetReconstructionModel(Int_t id, AliRICHClusterFinder *reconst)
 // Setter for the RICH reconstruction model (clusters)
 //
 
-    ((AliRICHChamber*) (*fChambers)[id])->ReconstructionModel(reconst);
+    ((AliRICHChamber*) (*fChambers)[id])->SetReconstructionModel(reconst);
 }
 
 void   AliRICH::SetNsec(Int_t id, Int_t nsec)
@@ -1373,7 +1715,6 @@ void AliRICH::StepManager()
     const  Float_t kBig=1.e10;
        
     TClonesArray &lhits = *fHits;
-    TGeant3 *geant3 = (TGeant3*) gMC;
     TParticle *current = (TParticle*)(*gAlice->Particles())[gAlice->CurrentTrack()];
 
  //if (current->Energy()>1)
@@ -1391,17 +1732,20 @@ void AliRICH::StepManager()
     pos[0]=position(0);
     pos[1]=position(1);
     pos[2]=position(2);
-    bzero((char *)ckovData,sizeof(ckovData)*19);
+    //bzero((char *)ckovData,sizeof(ckovData)*19);
     ckovData[1] = pos[0];                 // X-position for hit
     ckovData[2] = pos[1];                 // Y-position for hit
     ckovData[3] = pos[2];                 // Z-position for hit
+    ckovData[6] = 0;                      // dummy track length
     //ckovData[11] = gAlice->CurrentTrack();
+    
+    //printf("\n+++++++++++\nTrack: %d\n++++++++++++\n",gAlice->CurrentTrack());
 
     //AliRICH *RICH = (AliRICH *) gAlice->GetDetector("RICH"); 
     
     /********************Store production parameters for Cerenkov photons************************/ 
 //is it a Cerenkov photon? 
-    if (gMC->TrackPid() == 50000050) {          
+    if (gMC->TrackPid() == 50000050) { 
 
       //if (gMC->VolId("GAP ")==gMC->CurrentVolID(copy))
         //{                    
@@ -1410,10 +1754,12 @@ void AliRICH::StepManager()
          if  (ckovEnergy > 5.6e-09 && ckovEnergy < 7.8e-09 )       
            //if (ckovEnergy > 0)
            {
-             if (gMC->IsTrackEntering()){                                     //is track entering?
+             if (gMC->IsTrackEntering()){        //is track entering?
+               //printf("Track entered (1)\n");
                if (gMC->VolId("FRE1")==gMC->CurrentVolID(copy) || gMC->VolId("FRE2")==gMC->CurrentVolID(copy))
                  {                                                          //is it in freo?
-                   if (geant3->Gctrak()->nstep<1){                          //is it the first step?
+                   if (gMC->IsNewTrack()){                          //is it the first step?
+                     //printf("I'm in!\n");
                      Int_t mother = current->GetFirstMother(); 
                      
                      //printf("Second Mother:%d\n",current->GetSecondMother());
@@ -1421,16 +1767,18 @@ void AliRICH::StepManager()
                      ckovData[10] = mother;
                      ckovData[11] = gAlice->CurrentTrack();
                      ckovData[12] = 1;             //Media where photon was produced 1->Freon, 2->Quarz
+                     //printf("Produced in FREO\n");
                      fCkovNumber++;
                      fFreonProd=1;
                      //printf("Index: %d\n",fCkovNumber);
                    }    //first step question
                  }        //freo question
                
-               if (geant3->Gctrak()->nstep<1){                                  //is it first step?
+               if (gMC->IsNewTrack()){                                  //is it first step?
                  if (gMC->VolId("QUAR")==gMC->CurrentVolID(copy))             //is it in quarz?
                    {
                      ckovData[12] = 2;
+                     //printf("Produced in QUAR\n");
                    }    //quarz question
                }        //first step question
                
@@ -1441,10 +1789,12 @@ void AliRICH::StepManager()
                //if (fFreonProd == 1)
                {
                  if (gMC->IsTrackEntering()){                                     //is track entering?
-                   //printf("Got in");
+                   //printf("Track entered (2)\n");
+                   //printf("Current volume (should be META): %s\n",gMC->CurrentVolName());
+                   //printf("VolId: %d, CurrentVolID: %d\n",gMC->VolId("META"),gMC->CurrentVolID(copy));
                    if (gMC->VolId("META")==gMC->CurrentVolID(copy))                //is it in gap?      
                      {
-                       //printf("Got in\n");
+                       //printf("Got in META\n");
                        gMC->TrackMomentum(momentum);
                        mom[0]=momentum(0);
                        mom[1]=momentum(1);
@@ -1460,16 +1810,20 @@ void AliRICH::StepManager()
                        gMC->Rndm(ranf, 1);
                        //printf("grid calculation:%f\n",t);
                        if (ranf[0] > t) {
-                         //geant3->StopTrack();
+                         gMC->StopTrack();
                          ckovData[13] = 5;
                          AddCerenkov(gAlice->CurrentTrack(),vol,ckovData);
+                         //printf("Added One (1)!\n");
                          //printf("Lost one in grid\n");
                        }
                        /**********************************************************************************/
                      }    //gap
                    
+                   //printf("Current volume (should be CSI) (1): %s\n",gMC->CurrentVolName());
+                   //printf("VolId: %d, CurrentVolID: %d\n",gMC->VolId("CSI "),gMC->CurrentVolID(copy));
                    if (gMC->VolId("CSI ")==gMC->CurrentVolID(copy))             //is it in csi?      
                      {
+                       //printf("Got in CSI\n");
                        gMC->TrackMomentum(momentum);
                        mom[0]=momentum(0);
                        mom[1]=momentum(1);
@@ -1483,9 +1837,10 @@ void AliRICH::StepManager()
                        Float_t t = Fresnel(ckovEnergy*1e9,cophi,1);
                        gMC->Rndm(ranf, 1);
                        if (ranf[0] < t) {
-                         //geant3->StopTrack();
+                         gMC->StopTrack();
                          ckovData[13] = 6;
                          AddCerenkov(gAlice->CurrentTrack(),vol,ckovData);
+                         //printf("Added One (2)!\n");
                          //printf("Lost by Fresnel\n");
                        }
                        /**********************************************************************************/
@@ -1496,22 +1851,23 @@ void AliRICH::StepManager()
                  /********************Evaluation of losses************************/
                  /******************still in the old fashion**********************/
                  
-                 Int_t i1 = geant3->Gctrak()->nmec;            //number of physics mechanisms acting on the particle
+                 TArrayI procs;
+                 Int_t i1 = gMC->StepProcesses(procs);            //number of physics mechanisms acting on the particle
                  for (Int_t i = 0; i < i1; ++i) {
                    //        Reflection loss 
-                   if (geant3->Gctrak()->lmec[i] == 106) {        //was it reflected
+                   if (procs[i] == kPLightReflection) {        //was it reflected
                      ckovData[13]=10;
                      if (gMC->VolId("FRE1")==gMC->CurrentVolID(copy) || gMC->VolId("FRE2")==gMC->CurrentVolID(copy)) 
                        ckovData[13]=1;
                      if (gMC->CurrentVolID(copy) == gMC->VolId("QUAR")) 
                        ckovData[13]=2;
-                     //geant3->StopTrack();
+                     //gMC->StopTrack();
                      //AddCerenkov(gAlice->CurrentTrack(),vol,ckovData);
                    } //reflection question
-                   
-                   
+                    
                    //        Absorption loss 
-                   else if (geant3->Gctrak()->lmec[i] == 101) {              //was it absorbed?
+                   else if (procs[i] == kPLightAbsorption) {              //was it absorbed?
+                     //printf("Got in absorption\n");
                      ckovData[13]=20;
                      if (gMC->VolId("FRE1")==gMC->CurrentVolID(copy) || gMC->VolId("FRE2")==gMC->CurrentVolID(copy)) 
                        ckovData[13]=11;
@@ -1529,17 +1885,19 @@ void AliRICH::StepManager()
                      if (gMC->CurrentVolID(copy) == gMC->VolId("CSI ")) {
                        ckovData[13]=16;
                      }
-                     //geant3->StopTrack();
+                     gMC->StopTrack();
                      AddCerenkov(gAlice->CurrentTrack(),vol,ckovData);
+                     //printf("Added One (3)!\n");
                      //printf("Added cerenkov %d\n",fCkovNumber);
                    } //absorption question 
                    
                    
                    //        Photon goes out of tracking scope 
-                   else if (geant3->Gctrak()->lmec[i] == 30) {                 //is it below energy treshold?
+                   else if (procs[i] == kPStop) {                 //is it below energy treshold?
                      ckovData[13]=21;
-                     //geant3->StopTrack();
+                     gMC->StopTrack();
                      AddCerenkov(gAlice->CurrentTrack(),vol,ckovData);
+                     //printf("Added One (4)!\n");
                    }   // energy treshold question         
                  }  //number of mechanisms cycle
                  /**********************End of evaluation************************/
@@ -1557,7 +1915,9 @@ void AliRICH::StepManager()
       //printf("Cerenkov\n");
        if (gMC->VolId("CSI ")==gMC->CurrentVolID(copy))
        {
-           
+         //printf("Current volume (should be CSI) (2): %s\n",gMC->CurrentVolName());
+         //printf("VolId: %d, CurrentVolID: %d\n",gMC->VolId("CSI "),gMC->CurrentVolID(copy));
+         //printf("Got in CSI\n");
          if (gMC->Edep() > 0.){
                gMC->TrackPosition(position);
                gMC->TrackMomentum(momentum);
@@ -1648,6 +2008,7 @@ void AliRICH::StepManager()
                    //{
                    AddHit(gAlice->CurrentTrack(),vol,ckovData);
                    AddCerenkov(gAlice->CurrentTrack(),vol,ckovData);
+                   //printf("Added One (5)!\n");
                    //}
                }
            }
@@ -1832,7 +2193,7 @@ void AliRICH::FindClusters(Int_t nev,Int_t lastEntry)
          // Get ready the current chamber stuff
          //
          AliRICHResponse* response = iChamber->GetResponseModel();
-         AliRICHSegmentation*  seg = iChamber->GetSegmentationModel();
+         AliSegmentation*  seg = iChamber->GetSegmentationModel();
          AliRICHClusterFinder* rec = iChamber->GetReconstructionModel();
          if (seg) {      
              rec->SetSegmentation(seg);
@@ -1873,11 +2234,12 @@ void AliRICH::Streamer(TBuffer &R__b)
 {
     // Stream an object of class AliRICH.
     AliRICHChamber       *iChamber;
-    AliRICHSegmentation  *segmentation;
+    AliSegmentation  *segmentation;
     AliRICHResponse      *response;
     TClonesArray         *digitsaddress;
     TClonesArray         *rawcladdress;
-    TClonesArray         *rechitaddress;
+    TClonesArray         *rechitaddress1D;
+    TClonesArray         *rechitaddress3D;
       
     if (R__b.IsReading()) {
        Version_t R__v = R__b.ReadVersion(); if (R__v) { }
@@ -1888,11 +2250,13 @@ void AliRICH::Streamer(TBuffer &R__b)
        R__b >> fCerenkovs; // diff
        R__b >> fDchambers;
        R__b >> fRawClusters;
-       R__b >> fRecHits;  //diff
+       R__b >> fRecHits1D;  //diff
+       R__b >> fRecHits3D;  //diff
        R__b >> fDebugLevel;  //diff
        R__b.ReadStaticArray(fNdch);
        R__b.ReadStaticArray(fNrawch);
-       R__b.ReadStaticArray(fNrechits);
+       R__b.ReadStaticArray(fNrechits1D);
+       R__b.ReadStaticArray(fNrechits3D);
 //
        R__b >> fChambers;
 // Stream chamber related information
@@ -1905,8 +2269,10 @@ void AliRICH::Streamer(TBuffer &R__b)
            response->Streamer(R__b);     
            rawcladdress=(TClonesArray*) (*fRawClusters)[i];
            rawcladdress->Streamer(R__b);
-           rechitaddress=(TClonesArray*) (*fRecHits)[i];
-           rechitaddress->Streamer(R__b);
+           rechitaddress1D=(TClonesArray*) (*fRecHits1D)[i];
+           rechitaddress1D->Streamer(R__b);
+           rechitaddress3D=(TClonesArray*) (*fRecHits3D)[i];
+           rechitaddress3D->Streamer(R__b);
            digitsaddress=(TClonesArray*) (*fDchambers)[i];
            digitsaddress->Streamer(R__b);
        }
@@ -1937,12 +2303,14 @@ void AliRICH::Streamer(TBuffer &R__b)
        R__b << fCerenkovs; // diff
        R__b << fDchambers;
        R__b << fRawClusters;
-       R__b << fRecHits; //diff
+       R__b << fRecHits1D; //diff
+       R__b << fRecHits3D; //diff
        R__b << fDebugLevel; //diff
        R__b.WriteArray(fNdch, kNCH);
        R__b.WriteArray(fNrawch, kNCH);
-       R__b.WriteArray(fNrechits, kNCH);
-       //
+       R__b.WriteArray(fNrechits1D, kNCH);
+       R__b.WriteArray(fNrechits3D, kNCH);
+//
        R__b << fChambers;
 //  Stream chamber related information
        for (Int_t i =0; i<kNCH; i++) {
@@ -1954,8 +2322,10 @@ void AliRICH::Streamer(TBuffer &R__b)
            response->Streamer(R__b);
            rawcladdress=(TClonesArray*) (*fRawClusters)[i];
            rawcladdress->Streamer(R__b);
-           rechitaddress=(TClonesArray*) (*fRecHits)[i];
-           rechitaddress->Streamer(R__b);
+           rechitaddress1D=(TClonesArray*) (*fRecHits1D)[i];
+           rechitaddress1D->Streamer(R__b);
+           rechitaddress3D=(TClonesArray*) (*fRecHits3D)[i];
+           rechitaddress3D->Streamer(R__b);
            digitsaddress=(TClonesArray*) (*fDchambers)[i];
            digitsaddress->Streamer(R__b);
        }
@@ -2017,15 +2387,16 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
     static Bool_t first=kTRUE;
     static TFile *pFile;
     char *addBackground = strstr(option,"Add");
+    Int_t particle;
 
     FILE* points; //these will be the digits...
 
     points=fopen("points.dat","w");
 
     AliRICHChamber*       iChamber;
-    AliRICHSegmentation*  segmentation;
+    AliSegmentation*  segmentation;
 
-    Int_t digitse=0;
+    Int_t digitise=0;
     Int_t trk[50];
     Int_t chtrk[50];  
     TObjArray *list=new TObjArray;
@@ -2034,7 +2405,7 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
     Int_t digits[5]; 
     
     AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH");
-    AliRICHHitMap* pHitMap[10];
+    AliHitMap* pHitMap[10];
     Int_t i;
     for (i=0; i<10; i++) {pHitMap[i]=0;}
     if (addBackground ) {
@@ -2074,7 +2445,7 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
        }
     }
     
-    AliRICHHitMap* hm;
+    AliHitMap* hm;
     Int_t countadr=0;
     Int_t counter=0;
     for (i =0; i<kNCH; i++) {
@@ -2098,49 +2469,56 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
          mHit=(AliRICHHit*)pRICH->NextHit()) 
        {
          
-         digitse=0;
-         
          Int_t   nch   = mHit->fChamber-1;  // chamber number
+         Int_t   index = mHit->Track();
          if (nch >kNCH) continue;
          iChamber = &(pRICH->Chamber(nch));
          
-         TParticle *current = (TParticle*)(*gAlice->Particles())[track];
+         TParticle *current = (TParticle*)(*gAlice->Particles())[index];
          
-         Int_t particle = current->GetPdgCode();
+         if (current->GetPdgCode() >= 50000050)
+           {
+             TParticle *motherofcurrent = (TParticle*)(*gAlice->Particles())[current->GetFirstMother()];
+             particle = motherofcurrent->GetPdgCode();
+           }
+         else
+           {
+             particle = current->GetPdgCode();
+           }
+
          
          //printf("Flag:%d\n",flag);
          //printf("Track:%d\n",track);
          //printf("Particle:%d\n",particle);
          
-         if (flag == 0)
-           digitse=1;
+         digitise=1;
          
          if (flag == 1) 
-           if(TMath::Abs(particle) == 211 || TMath::Abs(particle) == 111)
-             digitse=1;
+           if(TMath::Abs(particle)==211 || TMath::Abs(particle)==111)
+             digitise=0;
          
          if (flag == 2)
            if(TMath::Abs(particle)==321 || TMath::Abs(particle)==130 || TMath::Abs(particle)==310 
               || TMath::Abs(particle)==311)
-             digitse=1;
+             digitise=0;
          
          if (flag == 3 && TMath::Abs(particle)==2212)
-           digitse=1;
+           digitise=0;
          
          if (flag == 4 && TMath::Abs(particle)==13)
-           digitse=1;
+           digitise=0;
          
          if (flag == 5 && TMath::Abs(particle)==11)
-           digitse=1;
+           digitise=0;
          
          if (flag == 6 && TMath::Abs(particle)==2112)
-           digitse=1;
+           digitise=0;
          
          
-         //printf ("Particle: %d, Flag: %d, Digitse: %d\n",particle,flag,digitse); 
+         //printf ("Particle: %d, Flag: %d, Digitise: %d\n",particle,flag,digitise); 
          
          
-         if (digitse)
+         if (digitise)
            {
              
              //
@@ -2150,7 +2528,6 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
                   mPad;
                   mPad=(AliRICHPadHit*)pRICH->NextPad(fPadHits))
                {
-                 Int_t cathode  = mPad->fCathode;    // cathode number
                  Int_t ipx      = mPad->fPadX;       // pad number on X
                  Int_t ipy      = mPad->fPadY;       // pad number on Y
                  Int_t iqpad    = mPad->fQpad;       // charge per pad
@@ -2158,9 +2535,9 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
                  //
                  //printf("X:%d, Y:%d, Q:%d\n",ipx,ipy,iqpad);
                  
-                 Float_t thex, they;
-                 segmentation=iChamber->GetSegmentationModel(cathode);
-                 segmentation->GetPadCxy(ipx,ipy,thex,they);
+                 Float_t thex, they, thez;
+                 segmentation=iChamber->GetSegmentationModel(0);
+                 segmentation->GetPadC(ipx,ipy,thex,they,thez);
                  new((*pAddress)[countadr++]) TVector(2);
                  TVector &trinfo=*((TVector*) (*pAddress)[countadr-1]);
                  trinfo(0)=(Float_t)track;
@@ -2249,14 +2626,13 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
                 mPad;
                 mPad=(AliRICHPadHit*)pRICH->NextPad(fClusters2))
              {
-               Int_t cathode  = mPad->fCathode;    // cathode number
                Int_t ipx      = mPad->fPadX;       // pad number on X
                Int_t ipy      = mPad->fPadY;       // pad number on Y
                Int_t iqpad    = mPad->fQpad;       // charge per pad
                
-               Float_t thex, they;
-               segmentation=iChamber->GetSegmentationModel(cathode);
-               segmentation->GetPadCxy(ipx,ipy,thex,they);
+               Float_t thex, they, thez;
+               segmentation=iChamber->GetSegmentationModel(0);
+               segmentation->GetPadC(ipx,ipy,thex,they,thez);
                Float_t rpad=TMath::Sqrt(thex*thex+they*they);
                if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
                new((*pAddress)[countadr++]) TVector(2);
@@ -2436,8 +2812,8 @@ Int_t AliRICH::MakePadHits(Float_t xhit,Float_t yhit,Float_t eloss, Int_t idvol,
 //  Calls the charge disintegration method of the current chamber and adds
 //  the simulated cluster to the root treee 
 //
-    Int_t clhits[kNCH];
-    Float_t newclust[6][500];
+    Int_t clhits[5];
+    Float_t newclust[4][500];
     Int_t nnew;
     
 //
@@ -2451,20 +2827,16 @@ Int_t AliRICH::MakePadHits(Float_t xhit,Float_t yhit,Float_t eloss, Int_t idvol,
 //
 //  Add new clusters
     for (Int_t i=0; i<nnew; i++) {
-       if (Int_t(newclust[3][i]) > 0) {
+       if (Int_t(newclust[0][i]) > 0) {
            ic++;
-// Cathode plane
-           clhits[1] = Int_t(newclust[5][i]);
 //  Cluster Charge
-           clhits[2] = Int_t(newclust[0][i]);
+           clhits[1] = Int_t(newclust[0][i]);
 //  Pad: ix
-           clhits[3] = Int_t(newclust[1][i]);
+           clhits[2] = Int_t(newclust[1][i]);
 //  Pad: iy 
-           clhits[4] = Int_t(newclust[2][i]);
-//  Pad: charge
-           clhits[5] = Int_t(newclust[3][i]);
+           clhits[3] = Int_t(newclust[2][i]);
 //  Pad: chamber sector
-           clhits[6] = Int_t(newclust[4][i]);
+           clhits[4] = Int_t(newclust[3][i]);
            
            AddPadHit(clhits);
        }