]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RICH/AliRICH.cxx
New gain variation diagnostics.
[u/mrichter/AliRoot.git] / RICH / AliRICH.cxx
index 608c3b1b8a9d62ed36b89b4aebe699ed1a115e10..73a0e47e75a00ae802ddcbc78e2d6a26767a8114 100644 (file)
 
 /*
   $Log$
+  Revision 1.42  2001/02/13 20:07:23  jbarbosa
+  Parametrised definition of photcathode dimensions. New spacers. New data members in AliRICHHit to store particle momentum
+  when entering the freon. Corrected calls to particle stack.
+
+  Revision 1.41  2001/01/26 20:00:20  hristov
+  Major upgrade of AliRoot code
+
+  Revision 1.40  2001/01/24 20:58:03  jbarbosa
+  Enhanced BuildGeometry. Now the photocathodes are drawn.
+
+  Revision 1.39  2001/01/22 21:40:24  jbarbosa
+  Removing magic numbers
+
+  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"
 
 
 #include "AliRICH.h"
 #include "AliSegmentation.h"
+#include "AliRICHSegmentationV0.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 "AliPDG.h"
 #include "AliPoints.h"
 #include "AliCallf77.h" 
-#include "TGeant3.h"
 
 
 // Static variables for the pad-hit iterator routines
@@ -126,13 +164,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;
 }
 
 //___________________________________________
@@ -159,7 +204,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;
    
@@ -181,12 +227,21 @@ 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)
@@ -205,6 +260,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;
+    }                     
+    
 }
 
 //___________________________________________
@@ -231,6 +309,26 @@ void AliRICH::AddCerenkov(Int_t track, Int_t *vol, Float_t *cerenkovs)
     //printf ("Done for Cerenkov %d\n\n\n\n",fNcerenkovs);
 }
 //___________________________________________
+void AliRICH::SDigits2Digits()
+{
+
+//
+// Gennerate digits
+//
+   AliRICHChamber*       iChamber;
+   
+   printf("Generating tresholds...\n");
+
+   for(Int_t i=0;i<7;i++) {
+       iChamber = &(Chamber(i));
+       iChamber->GenerateTresholds();
+   }
+       
+   int nparticles = gAlice->GetNtrack();
+   cout << "RICH: Particles       :" <<nparticles<<endl;
+   if (nparticles > 0) Digitise(0,0);
+}
+//___________________________________________
 void AliRICH::AddPadHit(Int_t *clhits)
 {
 
@@ -265,15 +363,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);
 }
 
 //___________________________________________
@@ -284,75 +394,224 @@ void AliRICH::BuildGeometry()
   //
   // Builds a TNode geometry for event display
   //
-    TNode *node, *top;
+    TNode *node, *subnode, *top;
     
-    const int kColorRICH = kGreen;
+    const int kColorRICH = kRed;
     //
     top=gAlice->GetGeometry()->GetNode("alice");
-    
+
+    AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH"); 
+    AliRICHSegmentationV0*  segmentation;
+    AliRICHChamber*       iChamber;
+
+    iChamber = &(pRICH->Chamber(0));
+    segmentation=(AliRICHSegmentationV0*) iChamber->GetSegmentationModel(0);
     
     new TBRIK("S_RICH","S_RICH","void",71.09999,11.5,73.15);
-    
+
+    Float_t padplane_width = segmentation->GetPadPlaneWidth();
+    Float_t padplane_length = segmentation->GetPadPlaneLength();
+
+    //printf("\n\n\n\n\n In BuildGeometry() npx: %d, npy: %d, dpx: %f, dpy:%f\n\n\n\n\n\n",segmentation->Npx(),segmentation->Npy(),segmentation->Dpx(),segmentation->Dpy());
+
+    new TBRIK("PHOTO","PHOTO","void", padplane_width/2,.1,padplane_length/2);
+
+    //printf("\n\n\n\n\n Padplane   w: %f l: %f \n\n\n\n\n", padplane_width/2,padplane_length/2);
+    //printf("\n\n\n\n\n Padplane   w: %f l: %f \n\n\n\n\n", segmentation->GetPadPlaneWidth(), segmentation->GetPadPlaneLength());
+  
+
     top->cd();
     Float_t pos1[3]={0,471.8999,165.2599};
     //Chamber(0).SetChamberTransform(pos1[0],pos1[1],pos1[2],
     new TRotMatrix("rot993","rot993",90,0,70.69,90,19.30999,-90);
     node = new TNode("RICH1","RICH1","S_RICH",pos1[0],pos1[1],pos1[2],"rot993");
-    
-
     node->SetLineColor(kColorRICH);
+    node->cd();
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
     fNodes->Add(node);
-    top->cd();
-    
+
+
+    top->cd(); 
     Float_t pos2[3]={171,470,0};
     //Chamber(1).SetChamberTransform(pos2[0],pos2[1],pos2[2],
     new TRotMatrix("rot994","rot994",90,-20,90,70,0,0);
     node = new TNode("RICH2","RICH2","S_RICH",pos2[0],pos2[1],pos2[2],"rot994");
-    
-    
     node->SetLineColor(kColorRICH);
+    node->cd();
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
     fNodes->Add(node);
+
+
     top->cd();
     Float_t pos3[3]={0,500,0};
     //Chamber(2).SetChamberTransform(pos3[0],pos3[1],pos3[2],
     new TRotMatrix("rot995","rot995",90,0,90,90,0,0);
     node = new TNode("RICH3","RICH3","S_RICH",pos3[0],pos3[1],pos3[2],"rot995");
-    
-
     node->SetLineColor(kColorRICH);
+    node->cd();
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
     fNodes->Add(node);
+
     top->cd();
     Float_t pos4[3]={-171,470,0};
     //Chamber(3).SetChamberTransform(pos4[0],pos4[1],pos4[2], 
     new TRotMatrix("rot996","rot996",90,20,90,110,0,0);  
     node = new TNode("RICH4","RICH4","S_RICH",pos4[0],pos4[1],pos4[2],"rot996");
-    
-
     node->SetLineColor(kColorRICH);
+    node->cd();
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
     fNodes->Add(node);
+
+
     top->cd();
     Float_t pos5[3]={161.3999,443.3999,-165.3};
     //Chamber(4).SetChamberTransform(pos5[0],pos5[1],pos5[2],
     new TRotMatrix("rot997","rot997",90,340,108.1999,70,18.2,70);
     node = new TNode("RICH5","RICH5","S_RICH",pos5[0],pos5[1],pos5[2],"rot997");
-    
     node->SetLineColor(kColorRICH);
+    node->cd();
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
     fNodes->Add(node);
+
+
     top->cd();
     Float_t pos6[3]={0., 471.9, -165.3,};
     //Chamber(5).SetChamberTransform(pos6[0],pos6[1],pos6[2],
     new TRotMatrix("rot998","rot998",90,0,109.3099,90,19.30999,90);
     node = new TNode("RICH6","RICH6","S_RICH",pos6[0],pos6[1],pos6[2],"rot998");
-    
-    
     node->SetLineColor(kColorRICH);
-    fNodes->Add(node);
+    
+    fNodes->Add(node);node->cd();
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+
+
     top->cd();
     Float_t pos7[3]={-161.399,443.3999,-165.3};
     //Chamber(6).SetChamberTransform(pos7[0],pos7[1],pos7[2],
     new TRotMatrix("rot999","rot999",90,20,108.1999,110,18.2,110);
     node = new TNode("RICH7","RICH7","S_RICH",pos7[0],pos7[1],pos7[2],"rot999");
     node->SetLineColor(kColorRICH);
+    node->cd();
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,padplane_length/2 + segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",padplane_width + segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
+    subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-padplane_width - segmentation->DeadZone(),0,-padplane_length/2 - segmentation->DeadZone()/2,"");
+    subnode->SetLineColor(kGreen);
+    fNodes->Add(subnode);
     fNodes->Add(node); 
     
 }
@@ -379,12 +638,12 @@ void AliRICH::CreateGeometry()
     //End_Html
 
   AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH"); 
-  AliSegmentation*  segmentation;
+  AliRICHSegmentationV0*  segmentation;
   AliRICHGeometry*  geometry;
   AliRICHChamber*       iChamber;
 
   iChamber = &(pRICH->Chamber(0));
-  segmentation=iChamber->GetSegmentationModel(0);
+  segmentation=(AliRICHSegmentationV0*) iChamber->GetSegmentationModel(0);
   geometry=iChamber->GetGeometryModel();
 
   Float_t distance;
@@ -393,8 +652,17 @@ void AliRICH::CreateGeometry()
     
   //Opaque quartz thickness
   Float_t oqua_thickness = .5;
-    
-    Int_t *idtmed = fIdtmed->GetArray()-999;
+  //CsI dimensions
+
+  //Float_t csi_length = 160*.8 + 2.6;
+  //Float_t csi_width = 144*.84 + 2*2.6;
+
+  Float_t csi_width = segmentation->Npx()*segmentation->Dpx() + segmentation->DeadZone();
+  Float_t csi_length = segmentation->Npy()*segmentation->Dpy() + 2*segmentation->DeadZone();
+  
+  //printf("\n\n\n\n\n In CreateGeometry() npx: %d, npy: %d, dpx: %f, dpy:%f  deadzone: %f \n\n\n\n\n\n",segmentation->Npx(),segmentation->Npy(),segmentation->Dpx(),segmentation->Dpy(),segmentation->DeadZone());
+  
+  Int_t *idtmed = fIdtmed->GetArray()-999;
     
     Int_t i;
     Float_t zs;
@@ -404,22 +672,36 @@ void AliRICH::CreateGeometry()
     // --- Define the RICH detector 
     //     External aluminium box 
     par[0] = 68.8;
-    par[1] = 11.5;                 //Original Settings
+    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] = 66.31;
-    par[1] = 11.5;                 //Original Settings
-    par[2] = 68.36;
+    //     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] = 66.3;
     par[1] = .188;                 //Original Settings
@@ -457,6 +739,13 @@ 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] = geometry->GetQuartzWidth()/2;
     par[1] = .2;
@@ -521,28 +810,28 @@ void AliRICH::CreateGeometry()
     
     //     Methane 
     //par[0] = 64.8;
-    par[0] = geometry->GetQuartzWidth()/2;
+    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] = geometry->GetQuartzLength()/2;
+    par[2] = csi_length/2;
     gMC->Gsvolu("META", "BOX ", idtmed[1004], par, 3);
     
     //     Methane gap 
     //par[0] = 64.8;
-    par[0] = geometry->GetQuartzWidth()/2;
+    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] = geometry->GetQuartzLength()/2;
+    par[2] = csi_length/2;
     gMC->Gsvolu("GAP ", "BOX ", idtmed[1008], par, 3);
     
     //     CsI photocathode 
     //par[0] = 64.8;
-    par[0] = geometry->GetQuartzWidth()/2;
+    par[0] = csi_width/2;
     par[1] = .25;
     //par[2] = 64.8;
-    par[2] = geometry->GetQuartzLength()/2;
+    par[2] = csi_length/2;
     gMC->Gsvolu("CSI ", "BOX ", idtmed[1005], par, 3);
     
     //     Anode grid 
@@ -550,83 +839,234 @@ 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 = 9;
+     //Placing of the spacers inside the freon slabs
+
+    Int_t nspacers = 30;
     //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);
     
-    //for (i = 1; i <= 9; ++i) {
-      //zs = (5 - i) * 14.4;                       //Original settings 
-    for (i = 0; i < nspacers; i++) {
-       zs = (TMath::Abs(nspacers/2) - i) * 14.4;
-       gMC->Gspos("SPAC", i, "FRE1", 6.7, 0., zs, idrotm[1019], "ONLY");  //Original settings 
-       //gMC->Gspos("SPAC", i, "FRE1", zs, 0., 6.7, idrotm[1019], "ONLY"); 
+    for (i = 0; i < nspacers/3; i++) {
+       zs = -11.6/2 + (TMath::Abs(nspacers/6) - i) * 12.2;
+       gMC->Gspos("SPAC", i, "FRE1", 10.5, 0., zs, idrotm[1019], "ONLY");  //Original settings 
+    }
+    
+    for (i = nspacers/3; i < (nspacers*2)/3; i++) {
+       zs = -11.6/2 + (nspacers/3 + TMath::Abs(nspacers/6) - i) * 12.2;
+       gMC->Gspos("SPAC", i, "FRE1", 0, 0., zs, idrotm[1019], "ONLY");  //Original settings 
+       printf("Spacer in %f\n", zs);
     }
-    //for (i = 10; i <= 18; ++i) {
-      //zs = (14 - i) * 14.4;                       //Original settings 
-    for (i = nspacers; i < nspacers*2; ++i) {
-       zs = (nspacers + TMath::Abs(nspacers/2) - i) * 14.4;
-       gMC->Gspos("SPAC", i, "FRE1", -6.7, 0., zs, idrotm[1019], "ONLY"); //Original settings  
-       //gMC->Gspos("SPAC", i, "FRE1", zs, 0., -6.7, idrotm[1019], "ONLY");  
+    
+    for (i = (nspacers*2)/3; i < nspacers; ++i) {
+       zs = -11.6/2 + ((nspacers*2)/3 + TMath::Abs(nspacers/6) - i) * 12.2;
+       gMC->Gspos("SPAC", i, "FRE1", -10.5, 0., zs, idrotm[1019], "ONLY"); //Original settings  
     }
 
-    //for (i = 1; i <= 9; ++i) {
-      //zs = (5 - i) * 14.4;                       //Original settings 
-      for (i = 0; i < nspacers; i++) {
-       zs = (TMath::Abs(nspacers/2) - i) * 14.4;
-       gMC->Gspos("SPAC", i, "FRE2", 6.7, 0., zs, idrotm[1019], "ONLY");  //Original settings 
-       //gMC->Gspos("SPAC", i, "FRE2", zs, 0., 6.7, idrotm[1019], "ONLY");
+    for (i = 0; i < nspacers/3; i++) {
+       zs = -11.6/2 + (TMath::Abs(nspacers/6) - i) * 12.2;
+       gMC->Gspos("SPAC", i, "FRE2", 10.5, 0., zs, idrotm[1019], "ONLY");  //Original settings 
     }
-    //for (i = 10; i <= 18; ++i) {
-      //zs = (5 - i) * 14.4;                       //Original settings 
-      for (i = nspacers; i < nspacers*2; ++i) {
-       zs = (nspacers + TMath::Abs(nspacers/2) - i) * 14.4;
-       gMC->Gspos("SPAC", i, "FRE2", -6.7, 0., zs, idrotm[1019], "ONLY");  //Original settings 
-       //gMC->Gspos("SPAC", i, "FRE2", zs, 0., -6.7, idrotm[1019], "ONLY");
+    
+    for (i = nspacers/3; i < (nspacers*2)/3; i++) {
+       zs = -11.6/2 + (nspacers/3 + TMath::Abs(nspacers/6) - i) * 12.2;
+       gMC->Gspos("SPAC", i, "FRE2", 0, 0., zs, idrotm[1019], "ONLY");  //Original settings 
     }
     
-    /*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", 31.3, -4.724, 41.3, 0, "ONLY");
-    gMC->Gspos("OQF2", 2, "SRIC", 0., -4.724, 0., 0, "ONLY");
-    gMC->Gspos("OQF1", 3, "SRIC", -31.3, -4.724, -41.3, 0, "ONLY");
-    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("QUAR", 1, "SRIC", 0., -3.974, 0., 0, "ONLY");
-    gMC->Gspos("GAP ", 1, "META", 0., 4.8, 0., 0, "ONLY");
-    gMC->Gspos("META", 1, "SRIC", 0., 1.276, 0., 0, "ONLY");
-    gMC->Gspos("CSI ", 1, "SRIC", 0., 6.526, 0., 0, "ONLY");*/
-
+    for (i = (nspacers*2)/3; i < nspacers; ++i) {
+       zs = -11.6/2 + ((nspacers*2)/3 + TMath::Abs(nspacers/6) - i) * 12.2;
+       gMC->Gspos("SPAC", i, "FRE2", -10.5, 0., zs, idrotm[1019], "ONLY"); //Original settings  
+    }
 
+    
     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)
+    printf("Opaque quartz in SRIC %f\n", 1.276 - geometry->GetGapThickness()/2- geometry->GetQuartzThickness() -geometry->GetFreonThickness()/2);
     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("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);
     
     //     Place RICH inside ALICE apparatus 
-  
+
+    // The placing of the chambers is measured from the vertex to the base of the methane vessel (490 cm)
+
+    //Float_t offset =  1.276 - geometry->GetGapThickness()/2;
+
     AliMatrix(idrotm[1000], 90., 0., 70.69, 90., 19.31, -90.);
     AliMatrix(idrotm[1001], 90., -20., 90., 70., 0., 0.);
     AliMatrix(idrotm[1002], 90., 0., 90., 90., 0., 0.);
@@ -841,8 +1281,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) {
@@ -917,6 +1355,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);
@@ -928,6 +1374,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;
@@ -945,18 +1393,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);
 }
 
 //___________________________________________
@@ -1177,58 +1628,79 @@ Int_t AliRICH::DistancetoPrimitive(Int_t , Int_t )
 }
 
 //___________________________________________
-void AliRICH::MakeBranch(Option_t* option)
+void AliRICH::MakeBranch(Option_t* option, char *file)
 {
   // Create Tree branches for the RICH.
     
     const Int_t kBufferSize = 4000;
     char branchname[20];
-    
-    
-    AliDetector::MakeBranch(option);
-    sprintf(branchname,"%sCerenkov",GetName());
-    if (fCerenkovs   && gAlice->TreeH()) {
-       gAlice->TreeH()->Branch(branchname,&fCerenkovs, kBufferSize);
-       printf("Making Branch %s for Cerenkov Hits\n",branchname);
-    }
-    
-    sprintf(branchname,"%sPadHits",GetName());
-    if (fPadHits   && gAlice->TreeH()) {
-       gAlice->TreeH()->Branch(branchname,&fPadHits, kBufferSize);
-       printf("Making Branch %s for PadHits\n",branchname);
+      
+    AliDetector::MakeBranch(option,file);
+   
+    char *cH = strstr(option,"H");
+    char *cD = strstr(option,"D");
+    char *cR = strstr(option,"R");
+
+    if (cH) {
+      sprintf(branchname,"%sCerenkov",GetName());
+      if (fCerenkovs   && gAlice->TreeH()) {
+        gAlice->MakeBranchInTree(gAlice->TreeH(), 
+                                 branchname, &fCerenkovs, kBufferSize, file) ;
+      }    
+      sprintf(branchname,"%sPadHits",GetName());
+      if (fPadHits   && gAlice->TreeH()) {
+        gAlice->MakeBranchInTree(gAlice->TreeH(), 
+                                 branchname, &fPadHits, kBufferSize, file) ;
+      }
     }
     
-// one branch for digits per chamber
-    Int_t i;
-    
-    for (i=0; i<kNCH ;i++) {
-       sprintf(branchname,"%sDigits%d",GetName(),i+1);
-       
-       if (fDchambers   && gAlice->TreeD()) {
-           gAlice->TreeD()->Branch(branchname,&((*fDchambers)[i]), kBufferSize);
-           printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
-       }       
+    if (cD) {
+    //
+    // one branch for digits per chamber
+    //
+      Int_t i;
+    
+      for (i=0; i<kNCH ;i++) {
+           sprintf(branchname,"%sDigits%d",GetName(),i+1);     
+           if (fDchambers   && gAlice->TreeD()) {
+           gAlice->MakeBranchInTree(gAlice->TreeD(), 
+                                    branchname, &((*fDchambers)[i]), kBufferSize, file) ;
+          printf("Making Branch %sDigits%d\n",GetName(),i+1);
+           }   
+      }
     }
 
-// one branch for raw clusters per chamber
-  for (i=0; i<kNCH ;i++) {
-      sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
-      
-      if (fRawClusters   && gAlice->TreeR()) {
-        gAlice->TreeR()->Branch(branchname,&((*fRawClusters)[i]), kBufferSize);
-        printf("Making Branch %s for raw clusters in chamber %d\n",branchname,i+1);
+    if (cR) {    
+    //
+    // one branch for raw clusters per chamber
+    //
+      Int_t i;
+
+      for (i=0; i<kNCH ;i++) {
+        sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
+        if (fRawClusters && gAlice->TreeR()) {
+           gAlice->MakeBranchInTree(gAlice->TreeR(), 
+                                    branchname, &((*fRawClusters)[i]), kBufferSize, file) ;
+        }        
+      }
+     //
+     // one branch for rec hits per chamber
+     // 
+     for (i=0; i<kNCH ;i++) {
+       sprintf(branchname,"%sRecHits1D%d",GetName(),i+1);    
+       if (fRecHits1D   && gAlice->TreeR()) {
+          gAlice->MakeBranchInTree(gAlice->TreeR(), 
+                                   branchname, &((*fRecHits1D)[i]), kBufferSize, file) ;
+       }       
+     }
+     for (i=0; i<kNCH ;i++) {
+       sprintf(branchname,"%sRecHits3D%d",GetName(),i+1);  
+       if (fRecHits3D   && gAlice->TreeR()) {
+          gAlice->MakeBranchInTree(gAlice->TreeR(), 
+                                   branchname, &((*fRecHits3D)[i]), kBufferSize, file) ;
       }        
-  }
-
-  // one branch for rec hits per chamber
-  for (i=0; i<kNCH ;i++) {
-    sprintf(branchname,"%sRecHits%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);
-    }  
-  }
+    }
+  }  
 }
 
 //___________________________________________
@@ -1275,13 +1747,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]));
+         }
+      } 
+      
   }
 }
 //___________________________________________
@@ -1303,7 +1783,7 @@ void AliRICH::ResetDigits()
   // Reset number of digits and the digits array for this detector
   //
     for ( int i=0;i<kNCH;i++ ) {
-       if ((*fDchambers)[i])   (*fDchambers)[i]->Clear();
+       if (fDchambers && (*fDchambers)[i])   (*fDchambers)[i]->Clear();
        if (fNdch)  fNdch[i]=0;
     }
 }
@@ -1321,15 +1801,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;
     }
 }
 
@@ -1377,17 +1870,6 @@ void   AliRICH::SetReconstructionModel(Int_t id, AliRICHClusterFinder *reconst)
     ((AliRICHChamber*) (*fChambers)[id])->SetReconstructionModel(reconst);
 }
 
-void   AliRICH::SetNsec(Int_t id, Int_t nsec)
-{
-
-//
-// Sets the number of padplanes
-//
-
-    ((AliRICHChamber*) (*fChambers)[id])->SetNsec(nsec);
-}
-
-
 //___________________________________________
 void AliRICH::StepManager()
 {
@@ -1398,7 +1880,7 @@ void AliRICH::StepManager()
     static Int_t   idvol;
     static Int_t   vol[2];
     Int_t          ipart;
-    static Float_t hits[18];
+    static Float_t hits[22];
     static Float_t ckovData[19];
     TLorentzVector position;
     TLorentzVector momentum;
@@ -1416,7 +1898,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)
@@ -1438,6 +1919,7 @@ void AliRICH::StepManager()
     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());
@@ -1459,7 +1941,7 @@ void AliRICH::StepManager()
                //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(); 
                      
@@ -1475,7 +1957,7 @@ void AliRICH::StepManager()
                    }    //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;
@@ -1511,7 +1993,7 @@ 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");
@@ -1538,7 +2020,7 @@ 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");
@@ -1552,21 +2034,22 @@ 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)) 
@@ -1585,7 +2068,7 @@ 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);
@@ -1593,9 +2076,9 @@ void AliRICH::StepManager()
                    
                    
                    //        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         
@@ -1670,11 +2153,14 @@ void AliRICH::StepManager()
                    ckovData[7]=cherenkovLoss;
                    
                    nPads = MakePadHits(localPos[0],localPos[2],cherenkovLoss,idvol,kCerenkov);
+                                   
                    if (fNPadHits > (Int_t)ckovData[8]) {
                        ckovData[8]= ckovData[8]+1;
                        ckovData[9]= (Float_t) fNPadHits;
                    }
 
+                   //printf("Cerenkov loss: %f\n", cherenkovLoss);
+
                    ckovData[17] = nPads;
                    //printf("nPads:%d",nPads);
                    
@@ -1730,6 +2216,14 @@ void AliRICH::StepManager()
          }*/
        if (gMC->VolId("FRE1")==gMC->CurrentVolID(copy) || gMC->VolId("FRE2")==gMC->CurrentVolID(copy))
          {
+           gMC->TrackMomentum(momentum);
+           mom[0]=momentum(0);
+           mom[1]=momentum(1);
+           mom[2]=momentum(2);
+           mom[3]=momentum(3);
+           hits [19] = mom[0];
+           hits [20] = mom[1];
+           hits [21] = mom[2];
            fFreonProd=1;
          }
 
@@ -1789,6 +2283,7 @@ void AliRICH::StepManager()
                hits[14] = mom[0];
                hits[15] = mom[1];
                hits[16] = mom[2];
+               hits[18] = 0;               // dummy cerenkov angle
 
                tlength = 0;
                eloss   = 0;
@@ -1883,7 +2378,7 @@ void AliRICH::FindClusters(Int_t nev,Int_t lastEntry)
 //
     for (Int_t icat=1;icat<2;icat++) {
        gAlice->ResetDigits();
-       gAlice->TreeD()->GetEvent(1); // spurious +1 ...
+       gAlice->TreeD()->GetEvent(0);
        for (Int_t ich=0;ich<kNCH;ich++) {
          AliRICHChamber* iChamber=(AliRICHChamber*) (*fChambers)[ich];
          TClonesArray *pRICHdigits  = this->DigitsAddress(ich);
@@ -1928,117 +2423,6 @@ void AliRICH::FindClusters(Int_t nev,Int_t lastEntry)
     //gObjectTable->Print();
 }
 
-
-//______________________________________________________________________________
-void AliRICH::Streamer(TBuffer &R__b)
-{
-    // Stream an object of class AliRICH.
-    AliRICHChamber       *iChamber;
-    AliSegmentation  *segmentation;
-    AliRICHResponse      *response;
-    TClonesArray         *digitsaddress;
-    TClonesArray         *rawcladdress;
-    TClonesArray         *rechitaddress;
-      
-    if (R__b.IsReading()) {
-       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
-       AliDetector::Streamer(R__b);
-       R__b >> fNPadHits;
-       R__b >> fPadHits;   // diff
-       R__b >> fNcerenkovs;
-       R__b >> fCerenkovs; // diff
-       R__b >> fDchambers;
-       R__b >> fRawClusters;
-       R__b >> fRecHits;  //diff
-       R__b >> fDebugLevel;  //diff
-       R__b.ReadStaticArray(fNdch);
-       R__b.ReadStaticArray(fNrawch);
-       R__b.ReadStaticArray(fNrechits);
-//
-       R__b >> fChambers;
-// Stream chamber related information
-       for (Int_t i =0; i<kNCH; i++) {
-           iChamber=(AliRICHChamber*) (*fChambers)[i];
-           iChamber->Streamer(R__b);
-           segmentation=iChamber->GetSegmentationModel();
-           segmentation->Streamer(R__b);
-           response=iChamber->GetResponseModel();
-           response->Streamer(R__b);     
-           rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-           rawcladdress->Streamer(R__b);
-           rechitaddress=(TClonesArray*) (*fRecHits)[i];
-           rechitaddress->Streamer(R__b);
-           digitsaddress=(TClonesArray*) (*fDchambers)[i];
-           digitsaddress->Streamer(R__b);
-       }
-      R__b >> fDebugLevel;
-      R__b >> fCkovNumber;
-      R__b >> fCkovQuarz;
-      R__b >> fCkovGap;
-      R__b >> fCkovCsi;
-      R__b >> fLostRfreo;
-      R__b >> fLostRquar;
-      R__b >> fLostAfreo;
-      R__b >> fLostAquarz;
-      R__b >> fLostAmeta;
-      R__b >> fLostCsi;
-      R__b >> fLostWires;
-      R__b >> fFreonProd;
-      R__b >> fMipx;
-      R__b >> fMipy;
-      R__b >> fFeedbacks;
-      R__b >> fLostFresnel;
-      
-    } else {
-       R__b.WriteVersion(AliRICH::IsA());
-       AliDetector::Streamer(R__b);
-       R__b << fNPadHits;
-       R__b << fPadHits; // diff
-       R__b << fNcerenkovs;
-       R__b << fCerenkovs; // diff
-       R__b << fDchambers;
-       R__b << fRawClusters;
-       R__b << fRecHits; //diff
-       R__b << fDebugLevel; //diff
-       R__b.WriteArray(fNdch, kNCH);
-       R__b.WriteArray(fNrawch, kNCH);
-       R__b.WriteArray(fNrechits, kNCH);
-       //
-       R__b << fChambers;
-//  Stream chamber related information
-       for (Int_t i =0; i<kNCH; i++) {
-           iChamber=(AliRICHChamber*) (*fChambers)[i];
-           iChamber->Streamer(R__b);
-           segmentation=iChamber->GetSegmentationModel();
-           segmentation->Streamer(R__b);
-           response=iChamber->GetResponseModel();
-           response->Streamer(R__b);
-           rawcladdress=(TClonesArray*) (*fRawClusters)[i];
-           rawcladdress->Streamer(R__b);
-           rechitaddress=(TClonesArray*) (*fRecHits)[i];
-           rechitaddress->Streamer(R__b);
-           digitsaddress=(TClonesArray*) (*fDchambers)[i];
-           digitsaddress->Streamer(R__b);
-       }
-      R__b << fDebugLevel;
-      R__b << fCkovNumber;
-      R__b << fCkovQuarz;
-      R__b << fCkovGap;
-      R__b << fCkovCsi;
-      R__b << fLostRfreo;
-      R__b << fLostRquar;
-      R__b << fLostAfreo;
-      R__b << fLostAquarz;
-      R__b << fLostAmeta;
-      R__b << fLostCsi;
-      R__b << fLostWires;
-      R__b << fFreonProd;
-      R__b << fMipx;
-      R__b << fMipy;
-      R__b << fFeedbacks;
-      R__b << fLostFresnel;
-    }
-}
 AliRICHPadHit* AliRICH::FirstPad(AliRICHHit*  hit,TClonesArray *clusters ) 
 {
 //
@@ -2165,11 +2549,11 @@ void AliRICH::Digitise(Int_t nev, Int_t flag, Option_t *option,Text_t *filename)
          if (nch >kNCH) continue;
          iChamber = &(pRICH->Chamber(nch));
          
-         TParticle *current = (TParticle*)(*gAlice->Particles())[index];
+         TParticle *current = (TParticle*)gAlice->Particle(index);
          
          if (current->GetPdgCode() >= 50000050)
            {
-             TParticle *motherofcurrent = (TParticle*)(*gAlice->Particles())[current->GetFirstMother()];
+             TParticle *motherofcurrent = (TParticle*)gAlice->Particle(current->GetFirstMother());
              particle = motherofcurrent->GetPdgCode();
            }
          else
@@ -2219,7 +2603,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
@@ -2228,7 +2611,7 @@ 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, thez;
-                 segmentation=iChamber->GetSegmentationModel(cathode);
+                 segmentation=iChamber->GetSegmentationModel(0);
                  segmentation->GetPadC(ipx,ipy,thex,they,thez);
                  new((*pAddress)[countadr++]) TVector(2);
                  TVector &trinfo=*((TVector*) (*pAddress)[countadr-1]);
@@ -2318,13 +2701,12 @@ 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, thez;
-               segmentation=iChamber->GetSegmentationModel(cathode);
+               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;
@@ -2505,35 +2887,33 @@ 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;
     
 //
 //  Integrated pulse height on chamber
     
     clhits[0]=fNhits+1;
-    
+
     ((AliRICHChamber*) (*fChambers)[idvol])->DisIntegration(eloss, xhit, yhit, nnew, newclust, res);
     Int_t ic=0;
     
 //
 //  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]);
+
+           //printf(" %d %d %d %d %d\n",  clhits[0],  clhits[1],  clhits[2],  clhits[3],  clhits[4]);
            
            AddPadHit(clhits);
        }