diff --git a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_01.xml b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_01.xml
index a1da4667959fef300391a3b19fc1b2642ea7afc4..73594f243ec3606cff347d4f4a68ca2e8c991991 100644
--- a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_01.xml
+++ b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_01.xml
@@ -28,7 +28,7 @@
 
     <constant name="SDT_chamber_layer_width" value="10*mm"/>
     <constant name="SDT_chamber_cell_width" value="10*mm"/>
-    <constant name="Epsilon" value="0*deg"/>
+    <constant name="Alpha" value="0*deg"/>
 
     <constant name="SDT_chamber_inner_wall_radius_min" value="SDT_chamber_radius_min-SDT_inner_wall_thickness"/>
     <constant name="SDT_chamber_inner_wall_radius_max" value="SDT_chamber_radius_min"/>
@@ -42,7 +42,7 @@
 
   <limits>
     <limitset name="DC_limits">
-      <limit name="step_length_max" particles="*" value="0.5" unit="mm" />
+      <limit name="step_length_max" particles="*" value="0.1" unit="mm" />
     </limitset>
   </limits>
 
@@ -53,8 +53,10 @@
 
   <detectors>
     <detector id="DetID_DC" name="DriftChamber" type="DriftChamber" readout="DriftChamberHitsCollection" vis="DCVis" sensitive="true" region="DriftChamberRegion" limits="DC_limits">
-      <chamber id="0"/>
-      <envelope>
+      <material name="Air"/>
+      <chamber id="0" material="GasHe_90Isob_10"/>
+      <side material="CarbonFiber"/>
+      <envelope vis="SeeThrough">
         <shape type="BooleanShape" operation="Union" material="Air">
           <shape type="Tube" rmin="SDT_radius_min" rmax="SDT_radius_max" dz="SDT_half_length" />
         </shape>
@@ -78,7 +80,7 @@
 
   <readouts>
     <readout name="DriftChamberHitsCollection">
-      <segmentation type="GridDriftChamber" cell_size="SDT_chamber_cell_width" epsilon0="Epsilon" detector_length="DC_length" identifier_phi="cellID" DC_rbegin="DC_chamber_layer_rbegin" DC_rend="DC_chamber_layer_rend" DC_rmin="SDT_chamber_radius_min" DC_rmax="SDT_chamber_radius_max" safe_distance="DC_safe_distance" layerID="layer" layer_width="SDT_chamber_layer_width"/>
+      <segmentation type="GridDriftChamber" cell_size="SDT_chamber_cell_width" detector_length="DC_length" identifier_phi="cellID" DC_rbegin="DC_chamber_layer_rbegin" DC_rend="DC_chamber_layer_rend" DC_rmin="SDT_chamber_radius_min" DC_rmax="SDT_chamber_radius_max" safe_distance="DC_safe_distance" layerID="layer" layer_width="SDT_chamber_layer_width"/>
 
       <!-- <id>system:8,chamber:1,layer:8,cellID:16</id> -->
       <id>system:5,layer:7:9,chamber:8,cellID:32:16</id>
diff --git a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_02.xml b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_02.xml
index ae4ccbe02f9e834bf72b242e8ee9ca15c839449a..0b6e8f67ebc42beb3446cf9b759b2e26e8cc60bb 100644
--- a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_02.xml
+++ b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_02.xml
@@ -28,7 +28,7 @@
 
     <constant name="SDT_chamber_layer_width" value="10*mm"/>
     <constant name="SDT_chamber_cell_width" value="10*mm"/>
-    <constant name="Epsilon" value="0*deg"/>
+    <constant name="Alpha" value="0*deg"/>
 
     <constant name="SDT_chamber_inner_wall_radius_min" value="SDT_chamber_radius_min-SDT_inner_wall_thickness"/>
     <constant name="SDT_chamber_inner_wall_radius_max" value="SDT_chamber_radius_min"/>
@@ -54,7 +54,9 @@
 
   <detectors>
     <detector id="DetID_DC" name="DriftChamber" type="DriftChamber" readout="DriftChamberHitsCollection" vis="DCVis" sensitive="true" insideTrackingVolume="true" limits="DC_limits">
-      <chamber id="0"/>
+      <material name="Air"/>
+      <chamber id="0" material="GasHe_90Isob_10"/>
+      <side material="CarbonFiber"/>
       <envelope>
         <shape type="BooleanShape" operation="Union" material="Air">
           <shape type="Tube" rmin="SDT_radius_min" rmax="SDT_radius_max" dz="SDT_half_length" />
@@ -79,7 +81,7 @@
 
   <readouts>
     <readout name="DriftChamberHitsCollection">
-      <segmentation type="GridDriftChamber" cell_size="SDT_chamber_cell_width" epsilon0="Epsilon" detector_length="DC_length" identifier_phi="cellID" DC_rbegin="DC_chamber_layer_rbegin" DC_rend="DC_chamber_layer_rend" DC_rmin="SDT_chamber_radius_min" DC_rmax="SDT_chamber_radius_max" safe_distance="DC_safe_distance" layerID="layer" layer_width="SDT_chamber_layer_width"/>
+      <segmentation type="GridDriftChamber" cell_size="SDT_chamber_cell_width" detector_length="DC_length" identifier_phi="cellID" DC_rbegin="DC_chamber_layer_rbegin" DC_rend="DC_chamber_layer_rend" DC_rmin="SDT_chamber_radius_min" DC_rmax="SDT_chamber_radius_max" safe_distance="DC_safe_distance" layerID="layer" layer_width="SDT_chamber_layer_width"/>
 
       <!-- <id>system:8,chamber:1,layer:8,cellID:16</id> -->
       <id>system:5,layer:7:9,chamber:8,cellID:32:16</id>
diff --git a/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml b/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml
index 4f631eb52d4fd73583c61db951c78630eab0e816..46959ebbe90bc0160e34d3b91b4e86255a41dd88 100644
--- a/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml
+++ b/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml
@@ -102,8 +102,10 @@
     <constant name="DC_chamber_layer_rbegin" value="800*mm"/>
     <constant name="DC_chamber_layer_rend" value="1800*mm"/>
 
+    <constant name="DC_chamber_safe_distance" value="10*mm"/>
+
     <constant name="DC_inner_radius" value="DC_chamber_layer_rbegin-SDT_inner_wall_thickness-DC_safe_distance"/>
-    <constant name="DC_outer_radius" value="DC_chamber_layer_rend+SDT_outer_wall_thickness+DC_safe_distance"/>
+    <constant name="DC_outer_radius" value="DC_chamber_layer_rend+DC_chamber_safe_distance+SDT_outer_wall_thickness+DC_safe_distance"/>
 
     <constant name="SIT1_inner_radius"   value="230*mm"/>
     <constant name="SIT2_inner_radius"   value="410*mm"/>
diff --git a/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml b/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml
index 9ede81b793e785ed44b1eb97b12b69af9ee48716..d8c788d2134f902cce02ffd6ec1e1daec2b35bde 100644
--- a/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml
+++ b/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml
@@ -32,7 +32,7 @@
   <include ref="../CRD_common_v01/VXD_v01_01.xml"/>
   <include ref="../CRD_common_v01/FTD_SkewRing_v01_01.xml"/>
   <include ref="../CRD_common_v01/SIT_SimplePixel_v01_01.xml"/>
-  <include ref="../CRD_common_v01/DC_Simple_v01_02.xml"/>
+  <include ref="../CRD_common_v01/DC_Simple_v01_03.xml"/>
   <include ref="../CRD_common_v01/SET_SimplePixel_v01_01.xml"/>
   
   <fields>
diff --git a/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml b/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml
index 4f631eb52d4fd73583c61db951c78630eab0e816..46959ebbe90bc0160e34d3b91b4e86255a41dd88 100644
--- a/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml
+++ b/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml
@@ -102,8 +102,10 @@
     <constant name="DC_chamber_layer_rbegin" value="800*mm"/>
     <constant name="DC_chamber_layer_rend" value="1800*mm"/>
 
+    <constant name="DC_chamber_safe_distance" value="10*mm"/>
+
     <constant name="DC_inner_radius" value="DC_chamber_layer_rbegin-SDT_inner_wall_thickness-DC_safe_distance"/>
-    <constant name="DC_outer_radius" value="DC_chamber_layer_rend+SDT_outer_wall_thickness+DC_safe_distance"/>
+    <constant name="DC_outer_radius" value="DC_chamber_layer_rend+DC_chamber_safe_distance+SDT_outer_wall_thickness+DC_safe_distance"/>
 
     <constant name="SIT1_inner_radius"   value="230*mm"/>
     <constant name="SIT2_inner_radius"   value="410*mm"/>
diff --git a/Detector/DetCRD/compact/CRD_o1_v02/CRD_o1_v02-onlyTracker.xml b/Detector/DetCRD/compact/CRD_o1_v02/CRD_o1_v02-onlyTracker.xml
index 2397761df6e9cb259db958cd691453c9b70f45ed..7f1a6986b8fc27630ee681d162002daa54df6f4c 100644
--- a/Detector/DetCRD/compact/CRD_o1_v02/CRD_o1_v02-onlyTracker.xml
+++ b/Detector/DetCRD/compact/CRD_o1_v02/CRD_o1_v02-onlyTracker.xml
@@ -31,7 +31,7 @@
   <include ref="../CRD_common_v01/VXD_v01_01.xml"/>
   <include ref="../CRD_common_v01/FTD_SkewRing_v01_01.xml"/>
   <include ref="../CRD_common_v01/SIT_SimplePixel_v01_01.xml"/>
-  <include ref="../CRD_common_v01/DC_Simple_v01_01.xml"/>
+  <include ref="../CRD_common_v01/DC_Simple_v01_03.xml"/>
   <include ref="../CRD_common_v01/SET_SimplePlanar_v01_01.xml"/>
 
   <fields>
diff --git a/Detector/DetDriftChamber/CMakeLists.txt b/Detector/DetDriftChamber/CMakeLists.txt
index fbf8e01ce18666fac8cda6937368dd0fd605c2b2..7321b5e644c092fdec4c075a1bdaabe492d8d93a 100644
--- a/Detector/DetDriftChamber/CMakeLists.txt
+++ b/Detector/DetDriftChamber/CMakeLists.txt
@@ -16,6 +16,7 @@ find_package(ROOT COMPONENTS MathCore GenVector Geom REQUIRED)
 
 gaudi_add_module(DetDriftChamber
                  SOURCES src/driftchamber/DriftChamber.cpp
+                 SOURCES src/driftchamber/DriftChamber_tile.cpp
 		 LINK DetSegmentation
                       ${DD4hep_COMPONENT_LIBRARIES} 
                   # ROOT Geant4
diff --git a/Detector/DetDriftChamber/compact/det.xml b/Detector/DetDriftChamber/compact/det.xml
index b62dd532daa4c15c48ae37228faeffe3fe32692f..08b29c928f6cd8b2bc10bb2ea39656e278509a09 100644
--- a/Detector/DetDriftChamber/compact/det.xml
+++ b/Detector/DetDriftChamber/compact/det.xml
@@ -19,7 +19,7 @@
 
 
   <define>
-    <constant name="world_size" value="2226*mm"/>
+    <constant name="world_size" value="2990*mm"/>
     <constant name="world_x" value="world_size"/>
     <constant name="world_y" value="world_size"/>
     <constant name="world_z" value="world_size"/>
@@ -40,8 +40,8 @@
 
     <constant name="DC_Endcap_dz" value="0.1*mm"/>
 
-    <constant name="SDT_half_length" value="2225*mm+DC_Endcap_dz"/>
-    <constant name="DC_half_length" value="2225*mm"/>
+    <constant name="SDT_half_length" value="2980*mm+DC_Endcap_dz"/>
+    <constant name="DC_half_length" value="2980*mm"/>
     <constant name="SDT_length" value="SDT_half_length*2"/>
     <constant name="DC_length" value="SDT_length-DC_Endcap_dz*2"/>
 
@@ -51,7 +51,7 @@
 
     <constant name="SDT_chamber_layer_width" value="10*mm"/>
     <constant name="SDT_chamber_cell_width" value="10*mm"/>
-    <constant name="Epsilon" value="0*deg"/>
+    <constant name="Alpha" value="0*deg"/>
 
     <constant name="SDT_chamber_inner_wall_radius_min" value="SDT_chamber_radius_min-SDT_inner_wall_thickness"/>
     <constant name="SDT_chamber_inner_wall_radius_max" value="SDT_chamber_radius_min"/>
@@ -74,7 +74,7 @@
 
   <limits>
     <limitset name="DC_limits">
-      <limit name="step_length_max" particles="*" value="0.1" unit="mm" />
+      <limit name="step_length_max" particles="*" value="0.5" unit="mm" />
     </limitset>
   </limits>
 
@@ -85,7 +85,9 @@
 
   <detectors>
     <detector id="DetID_DC" name="DriftChamber" type="DriftChamber" readout="DriftChamberHitsCollection" vis="VisibleBlue" sensitive="true" region="DriftChamberRegion" limits="DC_limits">
-      <chamber id="0"/>
+      <material name="Air"/>
+      <chamber id="0"  material="GasHe_90Isob_10"/>
+      <side material="CarbonFiber"/>
       <envelope vis="SeeThrough">
         <shape type="BooleanShape" operation="Union" material="Air">
           <shape type="Tube" rmin="SDT_radius_min" rmax="SDT_radius_max" dz="SDT_half_length" />
@@ -110,7 +112,7 @@
 
   <readouts>
     <readout name="DriftChamberHitsCollection">
-      <segmentation type="GridDriftChamber" cell_size="SDT_chamber_cell_width" epsilon0="Epsilon" detector_length="DC_length" identifier_phi="cellID" DC_rbegin="DC_chamber_layer_rbegin" DC_rend="DC_chamber_layer_rend" DC_rmin="SDT_chamber_radius_min" DC_rmax="SDT_chamber_radius_max" safe_distance="DC_safe_distance" layerID="layer" layer_width="SDT_chamber_layer_width"/>
+      <segmentation type="GridDriftChamber" cell_size="SDT_chamber_cell_width" detector_length="DC_length" identifier_phi="cellID" DC_rbegin="DC_chamber_layer_rbegin" DC_rend="DC_chamber_layer_rend" DC_rmin="SDT_chamber_radius_min" DC_rmax="SDT_chamber_radius_max" safe_distance="DC_safe_distance" layerID="layer" layer_width="SDT_chamber_layer_width"/>
 
 
       <id>system:5,layer:7:9,chamber:8,cellID:32:16</id>
diff --git a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
index be98c1c14fa100b5fd5a4199450fde98e9aebf72..02732bf5d8dea538f663d7c16afbb8733c8e7475 100644
--- a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
+++ b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
@@ -38,6 +38,9 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
     xml_coll_t c(x_det,_U(chamber));
     xml_comp_t x_chamber = c;
 
+    xml_coll_t cc(x_det,_U(side));
+    xml_comp_t x_side = cc;
+
     std::string det_name = x_det.nameStr();
     std::string det_type = x_det.typeStr();
 
@@ -45,6 +48,7 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
 
     // - global
     double chamber_half_length     = theDetector.constant<double>("DC_half_length");
+    double chamber_length  = theDetector.constant<double>("DC_length");
 
     // - chamber
     double chamber_radius_min = theDetector.constant<double>("SDT_chamber_radius_min");
@@ -60,7 +64,7 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
     int chamber_layer_number = floor((chamber_layer_rend-chamber_layer_rbegin)/chamber_layer_width);
 
     double safe_distance = theDetector.constant<double>("DC_safe_distance");
-    double epsilon = theDetector.constant<double>("Epsilon");
+    double alpha = theDetector.constant<double>("Alpha");
 
     // =======================================================================
     // Detector Construction
@@ -75,8 +79,10 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
     if( theDetector.buildType() == BUILD_ENVELOPE ) return sdet ;
 
 
-    dd4hep::Material det_mat(theDetector.material("Air"));
-    dd4hep::Material chamber_mat(theDetector.material("GasHe_90Isob_10"));
+//    dd4hep::Material det_mat(theDetector.material("Air"));
+    dd4hep::Material det_mat(theDetector.material(x_det.materialStr()));
+//    dd4hep::Material chamber_mat(theDetector.material("GasHe_90Isob_10"));
+    dd4hep::Material chamber_mat = theDetector.material(x_chamber.materialStr());
 
     // - global
     Assembly det_vol( det_name+"_assembly" ) ;
@@ -91,7 +97,8 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
     double chamber_outer_wall_rmin = theDetector.constant<double>("SDT_chamber_outer_wall_radius_min");
     double chamber_outer_wall_rmax = theDetector.constant<double>("SDT_chamber_outer_wall_radius_max");
 
-    dd4hep::Material wall_mat(theDetector.material("CarbonFiber"));
+//    dd4hep::Material wall_mat(theDetector.material("CarbonFiber"));
+    dd4hep::Material wall_mat(theDetector.material(x_side.materialStr()));
 
     double wall_rmin[2] = {chamber_inner_wall_rmin, chamber_outer_wall_rmin};
     double wall_rmax[2] = {chamber_inner_wall_rmax, chamber_outer_wall_rmax};
@@ -153,13 +160,14 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
     for(int layer_id = 0; layer_id < chamber_layer_number; layer_id++) {
         double rmin,rmax,offset=0;
         dd4hep::Volume* current_vol_ptr = nullptr;
-        current_vol_ptr = &det_chamber_vol;
+//        current_vol_ptr = &det_chamber_vol;
         rmin = chamber_layer_rbegin+(layer_id*chamber_layer_width);
         rmax = rmin+chamber_layer_width;
         layerIndex = layer_id;
 
         //Construction of drift chamber layers
         double rmid = delta_a_func(rmin,rmax);
+        double Rmid = rmid/std::cos(alpha/2);
         double ilayer_cir = 2 * M_PI * rmid;
         double ncell = ilayer_cir / chamber_layer_width;
         int ncell_layer = floor(ncell);
@@ -169,6 +177,8 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
         if(layer_id %2 ==0){ offset = 0.; }
         else { offset = 0.5 * layer_Phi; }
 
+        double epsilon = 0;
+
         DCHseg->setGeomParams(chamber_id, layerIndex, layer_Phi, rmid, epsilon, offset);
         DCHseg->setWiresInLayer(chamber_id, layerIndex, numWire);
 
diff --git a/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h b/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h
index 0233ccf829d16144cdc96513b85177d3bb4c2d33..ad9d036043e1df5883af31a7cf6cc37b0588d687 100644
--- a/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h
+++ b/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h
@@ -60,16 +60,19 @@ public:
   virtual CellID cellID(const Vector3D& aLocalPosition, const Vector3D& aGlobalPosition,
                         const VolumeID& aVolumeID) const;
   virtual double distanceTrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const;
+  virtual double distanceTrackWire2(const CellID& cID, const TVector3& hit_pos) const;
   virtual void cellposition(const CellID& cID, TVector3& Wstart, TVector3& Wend) const;
+  virtual void cellposition2(int chamber, int layer, int cell, TVector3& Wstart, TVector3& Wend) const;
   TVector3 LineLineIntersect(TVector3& p1, TVector3& p2, TVector3& p3, TVector3& p4) const;
   virtual TVector3 distanceClosestApproach(const CellID& cID, const TVector3& hitPos) const;
   virtual TVector3 Line_TrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const;
   virtual TVector3 IntersectionTrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const;
   virtual TVector3 wirePos_vs_z(const CellID& cID, const double& zpos) const;
+  virtual double Distance(const CellID& cID, const TVector3& pointIn, const TVector3& pointOut, TVector3& hitPosition) const;
 
 //  double phi(const CellID& cID) const;
   inline double cell_Size() const { return m_cellSize; }
-  inline double epsilon0() const { return m_epsilon0; }
+  inline double epsilon() const { return m_epsilon; }
   inline double detectorLength() const { return m_detectorLength; }
   inline double safe_distance() const { return m_safe_distance; }
   inline double layer_width() const { return m_layer_width; }
@@ -114,6 +117,52 @@ public:
 
   inline auto returnAllWires() const { return m_wiresPositions; }
 
+//  TVector3 LineLineIntersect(TVector3 p1, TVector3 p2, TVector3 p3, TVector3 p4) const {
+//    TVector3 p13, p43, p21;
+//    double d1343, d4321, d1321, d4343, d2121;
+//    double numer, denom;
+//    double mua, mub;
+//    TVector3 pa, pb;
+//
+//    p13.SetX(p1.X() - p3.X());
+//    p13.SetY(p1.Y() - p3.Y());
+//    p13.SetZ(p1.Z() - p3.Z());
+//    p43.SetX(p4.X() - p3.X());
+//    p43.SetY(p4.Y() - p3.Y());
+//    p43.SetZ(p4.Z() - p3.Z());
+//    /* if (ABS(p43.X())  < EPS && ABS(p43.Y())  < EPS && ABS(p43.Z())  < EPS) */
+//    /*    return(FALSE); */
+//    p21.SetX(p2.X() - p1.X());
+//    p21.SetY(p2.Y() - p1.Y());
+//    p21.SetZ(p2.Z() - p1.Z());
+//    /* if (ABS(p21.X())  < EPS && ABS(p21.Y())  < EPS && ABS(p21.Z())  < EPS) */
+//    /*    return(FALSE); */
+//
+//    d1343 = p13.X() * p43.X() + p13.Y() * p43.Y() + p13.Z() * p43.Z();
+//    d4321 = p43.X() * p21.X() + p43.Y() * p21.Y() + p43.Z() * p21.Z();
+//    d1321 = p13.X() * p21.X() + p13.Y() * p21.Y() + p13.Z() * p21.Z();
+//    d4343 = p43.X() * p43.X() + p43.Y() * p43.Y() + p43.Z() * p43.Z();
+//    d2121 = p21.X() * p21.X() + p21.Y() * p21.Y() + p21.Z() * p21.Z();
+//
+//    denom = d2121 * d4343 - d4321 * d4321;
+//    /* if (ABS(denom) < EPS) */
+//    /*    return(FALSE); */
+//    numer = d1343 * d4321 - d1321 * d4343;
+//
+//    mua = numer / denom;
+//    mub = (d1343 + d4321 * (mua)) / d4343;
+//
+//    pa.SetX(p1.X() + mua * p21.X());
+//    pa.SetY(p1.Y() + mua * p21.Y());
+//    pa.SetZ(p1.Z() + mua * p21.Z());
+//    pb.SetX(p3.X() + mub * p43.X());
+//    pb.SetY(p3.Y() + mub * p43.Y());
+//    pb.SetZ(p3.Z() + mub * p43.Z());
+//
+//    return pb - pa;
+//  }
+
+
   void updateParams(int chamber, int layer)  const{
     auto it_end = layer_params.cend();
     --it_end;
@@ -136,6 +185,15 @@ public:
     m_epsilon = Eps;
     m_offset = Offset;
  }
+   inline Vector3D returnPosWire0(double z) const {
+    double alpha = returnAlpha();
+    double t = 0.5 * (1 - 2.0 * z / m_detectorLength);
+    double x = _currentRadius * (1 + t * (std::cos(alpha) - 1));
+    double y = _currentRadius * t * std::sin(alpha);
+
+    Vector3D vec(x, y, z);
+    return vec;
+  }
 
 protected:
 
@@ -152,12 +210,12 @@ protected:
   }
 
   inline double returnAlpha() const {
-    double alpha = 2 * std::asin(m_detectorLength * std::tan(m_epsilon0)/(2 * _currentRadius));
+    double alpha = 2 * std::asin(m_detectorLength * std::tan(m_epsilon)/(2 * _currentRadius));
     return alpha;
  }
 
   double m_cellSize;
-  double m_epsilon0;
+//  double m_epsilon0;
   double m_detectorLength;
   double m_layer_width;
   double m_safe_distance;
diff --git a/Detector/DetSegmentation/src/GridDriftChamber.cpp b/Detector/DetSegmentation/src/GridDriftChamber.cpp
index a4302ebf59b180e9bf2abdc83fe2e3bb9e7ba9db..a2d0029c2c4e3fbaca6cf70166aa27f63823cb90 100644
--- a/Detector/DetSegmentation/src/GridDriftChamber.cpp
+++ b/Detector/DetSegmentation/src/GridDriftChamber.cpp
@@ -22,7 +22,7 @@ GridDriftChamber::GridDriftChamber(const BitFieldCoder* decoder) : Segmentation(
   _description = "Drift chamber segmentation in the global coordinates";
 
   registerParameter("cell_size", "cell size", m_cellSize, 1., SegmentationParameter::LengthUnit);
-  registerParameter("epsilon0", "epsilon", m_epsilon0, 0., SegmentationParameter::AngleUnit, true);
+//  registerParameter("epsilon0", "epsilon", m_epsilon0, 0., SegmentationParameter::AngleUnit, true);
   registerParameter("detector_length", "Length of the wire", m_detectorLength, 1., SegmentationParameter::LengthUnit);
   registerIdentifier("identifier_phi", "Cell ID identifier for phi", m_phiID, "cellID");
   registerIdentifier("layerID", "layer id", layer_id, "layer");
@@ -48,6 +48,10 @@ CellID GridDriftChamber::cellID(const Vector3D& /*localPosition*/, const Vector3
 
   double posx = globalPosition.X;
   double posy = globalPosition.Y;
+  double posz = globalPosition.Z;
+  Vector3D wire0 = returnPosWire0(posz);
+  double phi_wire0 = phiFromXY(wire0);
+
   double radius = sqrt(posx*posx+posy*posy);
 
   int m_DC_layer_number = floor((m_DC_rend-m_DC_rbegin)/m_layer_width);
@@ -58,7 +62,7 @@ CellID GridDriftChamber::cellID(const Vector3D& /*localPosition*/, const Vector3
       layerid = floor((radius - m_DC_rbegin)/DC_layerdelta);
   } else if ( radius>= (m_DC_rmin-m_safe_distance) && radius < m_DC_rbegin) {
       layerid = 0;
-  } else if ( radius> m_DC_rend && radius <= (m_DC_rmax+m_safe_distance)) {
+  } else if ( radius> m_DC_rend ) {//&& radius <= (m_DC_rmax+m_safe_distance)) {
       layerid = m_DC_layer_number-1;
   }
 
@@ -68,14 +72,30 @@ CellID GridDriftChamber::cellID(const Vector3D& /*localPosition*/, const Vector3
   double offsetphi= m_offset;
   int _lphi;
 
-  if(phi_hit >= offsetphi) {
-    _lphi = (int) ((phi_hit - offsetphi)/ _currentLayerphi);
+  if(phi_hit >= (offsetphi+phi_wire0)) {
+    _lphi = (int) ((phi_hit - offsetphi - phi_wire0)/ _currentLayerphi);
   }
   else {
-    _lphi = (int) ((phi_hit - offsetphi + 2 * M_PI)/ _currentLayerphi);
+    _lphi = (int) ((phi_hit - offsetphi - phi_wire0 + 2 * M_PI)/ _currentLayerphi);
   }
 
   int lphi = _lphi;
+
+std::cout << "#######################################: "
+          << " posx= " << posx
+          << " posy= " << posy
+          << " posz= " << posz
+          << " phi_hit: " << phi_hit
+          << " phi_wire0: " << phi_wire0
+          << " _lphi: " << _lphi
+          <<  " offset : " << m_offset
+          << " offsetphi: " << offsetphi
+          << " layerID: " << layerid
+          << " r: " << _currentRadius
+          << " layerphi: " << _currentLayerphi
+          << std::endl;
+
+
   _decoder->set(cID, layer_id, layerid);
   _decoder->set(cID, m_phiID, lphi);
 
@@ -102,6 +122,17 @@ void GridDriftChamber::cellposition(const CellID& cID, TVector3& Wstart,
   Wend = returnWirePosition(phi_end, 1);
 }
 
+void GridDriftChamber::cellposition2(int chamber,int layer, int cell,
+                                    TVector3& Wstart, TVector3& Wend) const {
+     updateParams(chamber,layer);
+     double phi_start = binToPosition(cell, _currentLayerphi, m_offset);
+     double phi_mid = phi_start + _currentLayerphi/2.;
+     double phi_end = phi_mid + returnAlpha();
+
+     Wstart = returnWirePosition(phi_mid, -1);
+     Wend = returnWirePosition(phi_end, 1);
+}
+
 TVector3 GridDriftChamber::LineLineIntersect(TVector3& p1, TVector3& p2, TVector3& p3, TVector3& p4) const {
 
   TVector3 p13, p43, p21;
@@ -171,6 +202,20 @@ double GridDriftChamber::distanceTrackWire(const CellID& cID, const TVector3& hi
   return DCA;
 }
 
+double GridDriftChamber::distanceTrackWire2(const CellID& cID, const TVector3& hit_pos) const {
+
+    TVector3 Wstart = {0,0,0};
+    TVector3 Wend = {0,0,0};
+    cellposition(cID,Wstart,Wend);
+
+    TVector3 denominator = Wend - Wstart;
+    TVector3  numerator = denominator.Cross(Wstart-hit_pos);
+
+    double DCA = numerator.Mag()/denominator.Mag() ;
+
+    return DCA;
+}
+
 TVector3 GridDriftChamber::distanceClosestApproach(const CellID& cID, const TVector3& hitPos) const {
   // Distance of the closest approach between a single hit (point) and the closest wire
 
@@ -253,6 +298,52 @@ TVector3 GridDriftChamber::IntersectionTrackWire(const CellID& cID, const TVecto
   return intersect;
 }
 
+double GridDriftChamber::Distance(const CellID& cID, const TVector3& pointIn, const TVector3& pointOut, TVector3& hitPosition) const {
+
+ //For two lines r=r1+t1.v1 & r=r2+t2.v2
+  //the closest approach is d=|(r2-r1).(v1 x v2)|/|v1 x v2|
+  //the point where closest approach are
+  //t1=(v1 x v2).[(r2-r1) x v2]/[(v1 x v2).(v1 x v2)]
+  //t2=(v1 x v2).[(r2-r1) x v1]/[(v1 x v2).(v1 x v2)]
+  //if v1 x v2=0 means two lines are parallel
+  //d=|(r2-r1) x v1|/|v1|
+
+  double t1,distance,dInOut,dHitIn,dHitOut;
+  //Get wirepoint @ endplate
+   TVector3 west = {0,0,0};
+   TVector3 east = {0,0,0};
+   cellposition(cID,west,east);
+   TVector3 wireLine=east - west;
+   TVector3 hitLine=pointOut - pointIn;
+
+  TVector3 hitXwire=hitLine.Cross(wireLine);
+  TVector3 wire2hit=east-pointOut;
+  //Hitposition is the position on hit line where closest approach
+  //of two lines, but it may out the area from pointIn to pointOut
+  if(hitXwire.Mag()==0){
+    distance=wireLine.Cross(wire2hit).Mag()/wireLine.Mag();
+    hitPosition=pointIn;
+  }else{
+    t1=hitXwire.Dot(wire2hit.Cross(wireLine))/hitXwire.Mag2();
+    hitPosition=pointOut+t1*hitLine;
+
+    dInOut=(pointOut-pointIn).Mag();
+    dHitIn=(hitPosition-pointIn).Mag();
+    dHitOut=(hitPosition-pointOut).Mag();
+    if(dHitIn<=dInOut && dHitOut<=dInOut){ //Between point in & out
+      distance=fabs(wire2hit.Dot(hitXwire)/hitXwire.Mag());
+    }else if(dHitOut>dHitIn){ // out pointIn
+      distance=wireLine.Cross(pointIn-east).Mag()/wireLine.Mag();
+      hitPosition=pointIn;
+    }else{ // out pointOut
+      distance=wireLine.Cross(pointOut-east).Mag()/wireLine.Mag();
+      hitPosition=pointOut;
+    }
+  }
+
+  return distance;
+}
+
 
 }
 }