Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETDetectorConstruction.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETDetectorConstruction.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETDetectorConstruction.cc	(revision 1316)
@@ -0,0 +1,670 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETDetectorConstruction.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "AXPETDetectorConstruction.hh"
+#include "AXPETDetectorMessenger.hh"
+
+//Solids
+#include "G4Box.hh"
+#include "G4Tubs.hh"
+#include "G4Sphere.hh"
+#include "G4Orb.hh"
+#include "G4Cons.hh"
+#include "G4Hype.hh"
+#include "G4Para.hh"
+#include "G4Paraboloid.hh"
+#include "G4Torus.hh"
+#include "G4Trd.hh"
+#include "G4Ellipsoid.hh"
+#include "G4EllipticalTube.hh"
+#include "G4EllipticalCone.hh"
+
+#include "G4Trap.hh"
+#include "G4Trd.hh"
+#include "G4Tet.hh"
+
+#include "G4Polycone.hh"
+#include "G4Polyhedra.hh"
+
+#include "G4TwistedTubs.hh"
+#include "G4TwistedBox.hh"
+#include "G4TwistedTrd.hh"
+#include "G4TwistedTrap.hh"
+
+#include "G4BooleanSolid.hh"
+#include "G4DisplacedSolid.hh"
+#include "G4UnionSolid.hh"
+#include "G4IntersectionSolid.hh"
+#include "G4SubtractionSolid.hh"
+#include "G4ReflectedSolid.hh"
+#include "G4RotationMatrix.hh"
+#include "G4BREPSolidBox.hh"
+//
+#include "G4LogicalVolume.hh"
+#include "G4PVPlacement.hh"
+#include "G4PVReplica.hh"
+#include "G4ThreeVector.hh"
+#include "G4RotationMatrix.hh"
+
+#include "G4RunManager.hh"
+#include "G4GeometryManager.hh"
+#include "G4PhysicalVolumeStore.hh"
+#include "G4LogicalVolumeStore.hh"
+#include "G4SolidStore.hh"
+
+#include "G4MaterialPropertiesTable.hh"
+#include "G4OpticalSurface.hh"
+#include "G4LogicalSkinSurface.hh"
+#include "G4LogicalBorderSurface.hh"
+#include "AXPETMaterial.hh"
+
+#include "G4VisAttributes.hh"
+#include "G4Colour.hh"
+
+#include "globals.hh"
+
+AXPETDetectorConstruction::AXPETDetectorConstruction():
+WorldVolume(0),LogWorldVolume(0),PhysWorldVolume(0), 
+						      LYSOVolume(0),LogLYSOVolume(0), PhysLYSOVolume(0)//, 
+  //InterVolume(0),LogInterVolume(0), PhysInterVolume(0), 
+  //DetecVolume(0),LogDetecVolume(0), PhysDetecVolume(0) 
+{
+ pttoMaterial = new AXPETMaterial();
+
+ worldXsize  = 20. *cm;
+ worldYsize  = 20. *cm;
+ worldZsize  = 20. *cm;
+
+ lysoIz   =  2.0 *mm;
+ lysoDz   =  0.1 *mm;
+ lysoR    =  6.0 *mm;
+
+ detectorMessenger = new AXPETDetectorMessenger(this);
+ fval="Tubs";
+
+ xRot=0.0;
+ yRot=0.0;
+ zRot=0.0;
+ fAbort=0;
+}
+
+AXPETDetectorConstruction::~AXPETDetectorConstruction()
+{    delete detectorMessenger;     }
+
+
+
+void AXPETDetectorConstruction::SwitchDetector()
+{
+   
+   G4RunManager::GetRunManager()->DefineWorldVolume(PhysWorldVolume);
+  
+}
+G4VSolid*
+AXPETDetectorConstruction::SelectDetector( const G4String& val )
+{
+
+  G4Box* b1 = new G4Box ( "b1", 1*mm, 0.5*mm, 0.50*mm );
+  G4Box* b2 = new G4Box ( "b2", 0.5*mm, 1*mm, 0.5*mm );
+
+  fval = val ;
+  G4double fTrackerR1,fTrackerR2,fPhi,fPhiSegment,fTheta,fThetaSegment ;  
+  G4double fSemiAxisX,fSemiAxisY,fSemiAxisZ  ;
+  G4double fTrackerR,fTrackerpDx1,fTrackerpDy1,fTrackerpDz;
+  if (val == "Sphere")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 = 0*mm ;
+      fTrackerR2 = (lysoR-0.01*mm)/2. ;
+      fPhi = 0*deg ;
+      fPhiSegment = 360*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 180*deg ;
+      aVolume = new G4Sphere ("aSphere",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+  }
+
+  else if (val == "HalfSphere")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 = 0. ;
+      fTrackerR2 = (lysoR-0.01*mm)/2. ;
+      fPhi = 0*deg ;
+      fPhiSegment = 180*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 180*deg ;
+      aVolume = new G4Sphere ("aHalfSphere",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if (val == "HollowSphere")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 = (lysoR-0.01*mm)/4.;
+      fTrackerR2 = (lysoR-0.01*mm)/2. ;
+      fPhi = 0*deg ;
+      fPhiSegment = 360*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 180*deg ;
+      aVolume = new G4Sphere ("aHollowSphere",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if (val == "HalfHollowSphere")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 0*deg ;
+      fPhiSegment = 180*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 180*deg ;
+      aVolume = new G4Sphere ("aHalfHollowSphere",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if (val == "Q1Shell")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 0*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ1Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if (val == "Q2Shell")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 90*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ2Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }  
+  else if (val == "Q3Shell")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 180*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ3Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if (val == "Q4Shell")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 270*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 0*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ4Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if (val == "Q5Shell")
+  {
+    // only solid sphere is supportet for now
+       fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 0*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 90*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ5Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+else if (val == "Q6Shell")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 90*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 90*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ5Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }  
+  else if (val == "Q7Shell")
+  {
+    // only solid sphere is supportet for now
+       fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 180*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 90*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ7Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if (val == "Q8Shell")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 270*deg ;
+      fPhiSegment = 90*deg ;
+      fTheta = 90*deg ;
+      fThetaSegment = 90*deg ;
+      aVolume = new G4Sphere ("aQ8Shell",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+
+
+  else if (val == "Shell")
+  {
+   
+ // Test for Problem Report with Optical Photons and Sphere or Ellipsoid
+     G4Sphere *newSOut = new G4Sphere("Crystal",0.,lysoR-0.01/mm,0,twopi,0,pi/2);
+     G4Sphere *newSIn = new G4Sphere("Crystal",0.,lysoR-4.01/mm,0,twopi,0,twopi);
+
+     // Box was added in user application in order to avoid problem with Sphere with theta=90 deg
+     // Not need anymore, this bug in Sphere was repared in 4.9.2.  
+     // G4Box* farMirrorBox2 = new G4Box("nearMirrorBox", lysoR-0.01/mm,
+     // lysoR-0.01/mm,  lysoR-0.01/mm);
+     // aVolume = new G4IntersectionSolid("GlassMirror", farMirrorBox2,shell,0,G4ThreeVector(0,0,-lysoR));
+   aVolume = new G4SubtractionSolid("OutsideminInside", newSOut, newSIn);     
+
+  }
+  else if (val == "Ring")
+  {
+    // only solid sphere is supportet for now
+      fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+      fTrackerR2 =(lysoR-0.01*mm)/2. ;
+      fPhi = 30*deg ;
+      fPhiSegment = 120*deg ;
+      fTheta = 10*deg ;
+      fThetaSegment = 40*deg ;
+      aVolume = new G4Sphere ("aRing",  fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
+
+  }
+  else if ( val == "Ellipsoid" ) {
+
+    fSemiAxisX = (lysoR-0.01*mm)/4. ;
+    fSemiAxisY = (lysoR-0.01*mm)/2. ;
+    fSemiAxisZ = (lysoR-0.01*mm)/2. ;
+
+    aVolume = new  G4Ellipsoid("aEllipsoid",
+			       fSemiAxisX,
+			       fSemiAxisY,
+			       fSemiAxisZ,
+			       -fSemiAxisX,fSemiAxisX);
+
+
+  }
+  else if (val == "Orb")
+  {
+
+    fTrackerR = (lysoR-0.01*mm)/2. ;
+    aVolume = new G4Orb ( "aOrb", fTrackerR );
+
+  }
+  else if (val == "Box") 
+  {         
+
+    fTrackerpDx1 = (lysoR-0.01*mm)/2. ;
+    fTrackerpDy1 = (lysoR-0.01*mm)/2. ;
+    fTrackerpDz  = (lysoR-0.01*mm)/2. ;
+
+    aVolume = new G4Box ( "aBox", fTrackerpDx1, fTrackerpDy1, fTrackerpDz );
+  }
+  else if (val == "Cons")
+  {        
+
+    fTrackerpDz =(lysoR-0.01*mm)/2.  ;
+    fTrackerR1 =(lysoR-0.01*mm)/4.  ;
+    fTrackerR2 =(lysoR-0.01*mm)/2.  ;
+
+    aVolume = new G4Cons ( "aCons", 0.8*fTrackerR1 , fTrackerR1, 0.8*fTrackerR2, fTrackerR2, fTrackerpDz, 10*deg, 220.*deg  ); 
+
+  }
+  else if (val == "manyCons")
+  {        
+    aVolume = new G4Cons ( "aCone", 2*mm, 3*mm, 2*mm, 4*mm,
+                           3.*mm, 10*deg, 300*deg ); 
+  //  10*cm, 10*deg, 300*deg ); 
+			   //  0., pi);
+
+ 
+  }
+  else if (val == "Tubs")
+  {
+
+    // only solid Tube is supported.
+  
+    aVolume = new G4Tubs ( "aTube",0.1,5.9*mm,3.*mm,0.,180*deg) ;
+
+  }
+  else if (val == "Hype")
+  {
+    aVolume = new G4Hype ("aHype", 0.7, 1, 40*deg, 40*deg, 4. );
+  }
+  else if (val == "Torus")
+  {
+
+    fPhi = 40*deg ;
+    fPhiSegment = 200*deg ;
+
+    fTrackerR1 = 1.*mm ;
+    fTrackerR2 = 2.*mm ;
+    fTrackerR  = (lysoR-0.01*mm) ;
+
+    aVolume = new G4Torus("aTorus", fTrackerR1, fTrackerR2 ,fTrackerR, fPhi, fPhiSegment) ;
+
+  }
+  else if (val == "Para")
+  {
+    aVolume = new G4Para ("aPara", 0.8, 1.0, 1.2, 30*deg, 45*deg, 60*deg);
+  }
+  else if (val == "Paraboloid")
+  {
+    aVolume = new G4Paraboloid ("aParaboloid", 1., 0.5, 1.2);
+  }
+  else if (val == "PolyconeGen")
+  {
+    G4double rr[]={1,1.20,1.40,1.20};
+    G4double zz[]={-1,-1,1,1};
+    aVolume = new G4Polycone ("aPolycone",0*deg,90*deg, 4, rr,zz);
+ }
+ else if (val == "PolyconeGenComplex")
+   { //has to be apdated
+    G4double        zPlanes[]       =       {-11640.*mm,    -11640.*mm,     -11570.722*mm,  -9766.005*mm,  
+                                                -4487.828*mm,   4487.828*mm,    9766.005*mm,    11570.722*mm,  
+                                                11640.*mm,      11640.*mm,      11580.*mm,      9750.*mm,
+					    4500.*mm,       -4500.*mm,      -9750.*mm,      -11580.*mm,
+					     -11640.*mm};
+  
+        G4double        radius[]        =       {250.*mm,       305.*mm,        305.*mm,        2770.461*mm,
+                                                4932.*mm,       4932.*mm,       2770.461*mm,    305.*mm,
+                                                305.*mm,        250.*mm,        250.*mm,        2750.*mm,
+						 4900.*mm,       4900.*mm,       2750.*mm,       250.*mm,
+						   250.*mm};
+	 aVolume = new G4Polycone ("aPolycone",0*deg,360*deg, 16, radius,zPlanes);
+    G4VSolid*       SolidPumpPort   =       new     G4Tubs("PumpPort temp tube", 0 * mm, 1750 / 2 * mm, (11161 - 4500) / 2 * mm-1*mm, 0, 360 * deg);
+           for (int i=0;i<2;i++)
+        {
+	       G4RotationMatrix*       Rot     =       new G4RotationMatrix();
+	       Rot->rotateZ(45*(-i-1) * deg );
+                G4double        X       =       std::cos(45*(i+1)*deg)*-(3050+4750)/2*mm;
+                G4double        Y       =       std::sin(45*(i+1)*deg)*-(3050+4750)/2*mm;
+                aVolume        =       new G4SubtractionSolid("Main Spectrometer", aVolume, SolidPumpPort,
+            Rot, G4ThreeVector(X, Y,(11161+4500)/2*mm - 100 * mm));
+	 }
+
+
+
+ }
+  else if (val == "Polycone")
+  {
+    G4double rIn[]={1.00,1.20,0,0,1.20,1.20};
+    G4double rOut[]={1.20,1.40,1.40,1.20,1.40,1.60};
+    G4double zPlane[]={-2.00,-1.00,0,1.00,2.00,3.00};
+    aVolume = new G4Polycone ("aPolycone",0*deg,260*deg, 6,zPlane, rIn,rOut);
+  }
+ else if (val == "PolyhedraGen")
+  {
+    G4double rr[]={1.00,1.20,1.40,1.20};
+    G4double zz[]={-1.00,-1.00,1.00,1.00};
+    aVolume = new G4Polyhedra ("aPolycone",0*deg,90*deg,8, 4, rr,zz);
+  }
+ else if (val == "PolyhedraGenComplex")
+  {
+    G4double rr[]={ 1.00, 1.20,   0,  0,1.40,1.20,1.50,1.50,1.50,1.40, 1.30};
+    G4double zz[]={-1.50,-1.00,-1.00,-0.50,  0,2.00,2.00,1.00,0,  -0.50,-1.00};
+    aVolume = new G4Polyhedra ("aPolycone",0*deg,260*deg,8, 11, rr,zz);
+  }
+ else if (val == "Polyhedra")
+  {
+    G4double rOut[5]={2.100,0.600,1.500,1.500,3.800};
+    G4double rIn[5]={0,0.500,0,0.700,0.100};
+    G4double zPlane[5]={-0.100,1.000,1.500,2.500,3.000};
+    aVolume = new G4Polyhedra ("aPolycone",0*deg,260*deg,6, 5,zPlane, rIn,rOut);
+  }
+ 
+  else if (val == "Trd")
+  {
+    aVolume = new G4Trd ("aTrd", 0.80, 1.00, 0.70,0.90, 1.00);
+  }
+  else if (val == "b1Ub2") 
+  {         
+    aVolume = new G4UnionSolid("b1Ub2",b1,b2);
+  
+  }
+  else if (val == "b1Ib2") 
+  {         
+    aVolume = new G4IntersectionSolid("b1Ib2",b1,b2);
+  }
+  else if (val == "b1Sb2") 
+  {         
+    aVolume = new G4SubtractionSolid("b1Sb2",b1,b2);
+  }
+  else if (val == "b1Ib1") 
+  {         
+    aVolume = new G4IntersectionSolid("b1Ib1",b1,b1);
+  }
+  else if (val == "b1Ub1") 
+  {         
+    aVolume = new G4UnionSolid("b1Ub1",b1,b1);
+  }
+  else if (val == "b1Sb1") 
+  {         
+    aVolume = new G4SubtractionSolid("b1Sb1",b1,b1);
+  }
+
+  else if ( val == "Tet" ) 
+  {
+
+      G4ThreeVector pzero(0,0,0);
+      G4ThreeVector pnt1(1.,0.,0.),pnt2(0,1.,0.), pnt3(0,0.,1.);
+      G4Tet   t1( "aTet", pzero, pnt1, pnt2, pnt3);
+  }
+  else if ( val == "Trap") 
+  {
+      fTrackerpDz = 0.80;
+    fTheta = 10*deg ;
+    fPhi  =  40*deg ;
+    fTrackerpDy1 = 1.6 ;
+    fTrackerpDx1 = 2.4 ;
+    G4double fTrackerpDx2 = 1.4 ;
+    G4double fTrackerpDy2 = 0.8 ;
+    G4double fTrackerpDx3 = 1.6 ;
+    G4double fTrackerpDx4 = 1.1 ;
+    G4double fAlph = 50*deg    ;
+
+    aVolume = new G4Trap("aTrap",
+				fTrackerpDz,         // half z length
+				fTheta,              // direction between end planes
+				fPhi,                // defined by polar and azimutal angles.
+				fTrackerpDy1,        // half y length at -pDz
+				fTrackerpDx1,        // half x length at -pDz,-pDy
+				fTrackerpDx2,        // half x length at -pDz,+pDy
+				fAlph,                // tilt angle at +pDz
+				fTrackerpDy2,        // half y length at +pDz
+				fTrackerpDx3,        // half x length at +pDz,-pDy
+				fTrackerpDx4,        // half x length at +pDz,+pDy
+				fAlph                // tilt angle at +pDz
+				) ;
+    
+ 
+  }
+  else if ( val == "EllipticalCone" ) 
+  {
+    aVolume = new G4EllipticalCone("aEllipticalCone",
+                        0.5,       // xSemiAxis
+                        1,       // ySemiAxis
+                        4.0,      // zheight
+                        2.5) ;    // zTopCut
+
+  }
+  else if ( val == "EllipticalTube" ) 
+  {
+    aVolume = new G4EllipticalTube("aEllipticalTube" ,
+				   2,   // xSemiAxis
+				   4,   // ySemiAxis
+				   3.5) ;  // zheight
+
+  }
+  else
+    { G4cout <<"DetectorConstruction tried to select "<<val<<G4endl;
+    G4Exception("DetectorConstruction::SelectDetector() - Invalid shape!");
+  }
+
+  return aVolume;
+
+}
+G4VPhysicalVolume* AXPETDetectorConstruction::Construct()
+{
+ //***********************************************
+  // Clear all Stores
+  //***********************************************
+
+   G4GeometryManager::GetInstance()->OpenGeometry();
+   G4PhysicalVolumeStore::GetInstance()->Clean();
+   G4LogicalVolumeStore::GetInstance()->Clean();
+   G4SolidStore::GetInstance()->Clean();
+
+ pttoMaterial->DefineMaterials();
+ 
+ air = pttoMaterial->GetMat("AIR");
+ lyso= pttoMaterial->GetMat("LYSO");
+ vacuum= pttoMaterial->GetMat("Galactic");
+
+
+  //***********************************************
+  // Defining the world volume
+  //***********************************************
+
+ WorldVolume = new G4Box("World",worldXsize,worldYsize,worldZsize);
+
+ LogWorldVolume = new G4LogicalVolume(WorldVolume, 
+                                           vacuum, 
+                                           "logicWorld", 
+					    0,0,0);
+
+ PhysWorldVolume = new G4PVPlacement(0, G4ThreeVector(),
+					 "physicalWorld", 
+					  LogWorldVolume, 
+					  0,false,0);
+
+
+  //***********************************************
+  // Defining the lyso-Solid volume
+  //***********************************************
+
+ 
+ LYSOVolume=SelectDetector(fval);
+ LogLYSOVolume = new G4LogicalVolume(LYSOVolume, 
+                                        lyso, 
+                                        "logicLYSO", 
+					 0,0,0);
+
+ G4RotationMatrix *mat=new G4RotationMatrix();
+ if(xRot!=0.)mat->rotateX(xRot*deg);
+ if(yRot!=0.)mat->rotateY(xRot*deg);
+ if(zRot!=0.)mat->rotateZ(xRot*deg);
+ // mat->rotateY(180.*deg);
+ // mat->rotateZ(10.*deg);
+ G4ThreeVector position=G4ThreeVector(1.0,1.0,1.0);
+
+ PhysLYSOVolume = new G4PVPlacement(mat,G4ThreeVector(0.0,0.0,0.0),
+  					LogLYSOVolume,
+					"physicalLYSO", 
+				      LogWorldVolume, 
+				    	 0,false,0);
+					 
+  G4cout << "The LYSO crystal is built as "<<fval << G4endl;
+
+
+
+
+  //************************************************************************
+  //Al coated surface properties
+  //************************************************************************
+
+  const G4int nEntries = 11;
+  const G4double refl = 0.85;
+  
+  G4double PhotonEnergy[nEntries] = {2.478*eV, 2.53*eV, 2.58*eV, 2.636*eV, 2.69*eV, 2.75*eV, 2.816*eV, 2.88*eV, 2.95*eV, 3.022*eV, 3.097*eV};
+
+  G4double Reflectivity[nEntries]   = {refl, refl,refl, refl, refl, refl, refl, refl, refl, refl, refl};
+  G4double Efficiency[nEntries]     = {0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0}; 
+  G4double specularlobe[nEntries]   = {0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0}; 
+  G4double specularspike[nEntries]  = {0.9, 0.9,0.9, 0.9,0.9, 0.9,0.9, 0.9,0.9, 0.9,0.9}; 
+  G4double backscatter[nEntries]    = {0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0}; 
+  G4double rindex[nEntries]         = {1.39, 1.39,1.39, 1.39,1.39,1.39,1.39, 1.39,1.39, 1.39,1.39}; 
+
+
+  G4OpticalSurface* alcoated_opsurf=  new G4OpticalSurface("alcoated_opsurf");
+   new G4LogicalBorderSurface("alcoated_surf",PhysLYSOVolume,PhysWorldVolume, alcoated_opsurf);
+ 
+
+  G4MaterialPropertiesTable* alcoated_mt = new G4MaterialPropertiesTable();
+  alcoated_mt->AddProperty("RINDEX",  PhotonEnergy,rindex,  nEntries );
+  alcoated_mt->AddProperty("EFFICIENCY",  PhotonEnergy,Efficiency,  nEntries );
+  alcoated_mt->AddProperty("REFLECTIVITY",PhotonEnergy,Reflectivity,nEntries);
+  alcoated_mt->AddProperty("SPECULARLOBECONSTANT",PhotonEnergy,specularlobe,nEntries);
+  alcoated_mt->AddProperty("SPECULARSPIKECONSTANT",PhotonEnergy,specularspike,nEntries);
+  alcoated_mt->AddProperty("BACKSCATTERCONSTANT",PhotonEnergy,backscatter,nEntries);
+
+
+  alcoated_opsurf->SetType(dielectric_metal);
+  alcoated_opsurf->SetModel(unified);
+  alcoated_opsurf->SetFinish(groundbackpainted/*polished*/);
+  
+
+  alcoated_opsurf->SetMaterialPropertiesTable(alcoated_mt);
+
+
+  G4VisAttributes* WhiteVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));//red
+  WhiteVisAtt->SetVisibility(true);
+  WhiteVisAtt->SetForceSolid(true);
+
+  G4VisAttributes* LysoVisAtt= new G4VisAttributes(G4Colour(0.0,0.0,1.0));//red
+  LysoVisAtt->SetVisibility(true);
+  LysoVisAtt->SetForceSolid(true);
+
+  G4VisAttributes* DeteVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));//yellow
+  DeteVisAtt->SetVisibility(true);
+  DeteVisAtt->SetForceSolid(true);
+  
+  LogLYSOVolume->SetVisAttributes(LysoVisAtt);
+  LogWorldVolume->SetVisAttributes(G4VisAttributes::GetInvisible());
+
+  return PhysWorldVolume;
+ 
+ }
+
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETDetectorMessenger.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETDetectorMessenger.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETDetectorMessenger.cc	(revision 1316)
@@ -0,0 +1,133 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETDetectorMessenger.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "AXPETDetectorMessenger.hh"
+
+#include "AXPETDetectorConstruction.hh"
+#include "G4UIdirectory.hh"
+#include "G4UIcmdWithAString.hh"
+#include "G4UIcmdWithADouble.hh"
+#include "G4UIcmdWithAnInteger.hh"
+#include "globals.hh"
+
+#include "G4ios.hh"
+
+AXPETDetectorMessenger::AXPETDetectorMessenger(AXPETDetectorConstruction * myDC)
+  : myDetector(myDC)
+{
+  G4String defParam;
+
+  mydetDir = new G4UIdirectory("/mydet/");
+  mydetDir->SetGuidance("Detector setup commands.");
+
+  selDetCmd = new G4UIcmdWithAString("/mydet/SelectDetector",this);
+  selDetCmd->SetGuidance("Select Detector Setup.");
+  selDetCmd->SetGuidance("  Choice : Detector type ");
+  selDetCmd->SetParameterName("choice",true);
+  selDetCmd->SetDefaultValue("Tubs");
+
+ selDetCmd->SetCandidates("Trap Trd Tet Sphere HalfSphere HollowSphere HalfHollowSphere  Ring Shell Orb Box Cons manyCons Tubs Hype Torus Para Paraboloid Polycone PolyconeGen PolyconeGenComplex Polyhedra PolyhedraGen PolyhedraGenComplex BREPBox Trd b1Ib2 b1Ub2 b1Sb2 b1Ub1 b1Ib1 b1Sb1 Ellipsoid EllipticalCone EllipticalTube");
+  selDetCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
+
+  rotXCmd = new G4UIcmdWithADouble("/mydet/RotateX",this);
+  rotXCmd->SetGuidance("Rotation in X direction ");
+  rotXCmd->SetGuidance("  Choice : deg");
+  rotXCmd->SetParameterName("choice",true);
+  rotXCmd->SetDefaultValue(0.0);
+  rotXCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
+
+  rotYCmd = new G4UIcmdWithADouble("/mydet/RotateY",this);
+  rotYCmd->SetGuidance("Rotation in Y direction ");
+  rotYCmd->SetGuidance("  Choice : deg");
+  rotYCmd->SetParameterName("choice",true);
+  rotYCmd->SetDefaultValue(0.0);
+  rotYCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
+ 
+  rotZCmd = new G4UIcmdWithADouble("/mydet/RotateZ",this);
+  rotZCmd->SetGuidance("Rotation in Z direction ");
+  rotZCmd->SetGuidance("  Choice : deg");
+  rotZCmd->SetParameterName("choice",true);
+  rotZCmd->SetDefaultValue(0.0);
+  rotZCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
+
+  AbortCmd = new G4UIcmdWithAnInteger("/mydet/AbortRun",this);
+  AbortCmd->SetGuidance("Abortion of Run instead of Warnings  ");
+  AbortCmd->SetGuidance("  Choice : 0/1");
+  AbortCmd->SetParameterName("choice",true);
+  AbortCmd->SetDefaultValue(0);
+  AbortCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
+
+  // myDetector->SelectDetector(defParam="Tubs");
+   myDetector->SetDetectorName(defParam="Tubs");
+   myDetector->Construct();
+
+
+
+
+}
+AXPETDetectorMessenger::~AXPETDetectorMessenger() {
+  delete rotXCmd;
+  delete rotYCmd;
+  delete rotZCmd;
+  delete AbortCmd;
+  delete selDetCmd;
+}
+void AXPETDetectorMessenger::SetNewValue(G4UIcommand * command,
+                                         G4String newValues)
+{
+  if( command == selDetCmd )
+  {
+    //myDetector->SelectDetector(newValues);
+    myDetector->SetDetectorName(newValues);
+    myDetector->Construct();
+    myDetector->SwitchDetector();
+  }
+  if( command == rotXCmd)
+  {
+    myDetector->SetRotationInX(rotXCmd->GetNewDoubleValue(newValues));
+  }
+   if( command == rotYCmd)
+  {
+    myDetector->SetRotationInY(rotYCmd->GetNewDoubleValue(newValues));
+  }
+   if( command == rotZCmd)
+  {
+    myDetector->SetRotationInZ(rotZCmd->GetNewDoubleValue(newValues));
+  }
+
+ if( command == AbortCmd)
+  {
+    myDetector->SetAbortAction(AbortCmd->GetNewIntValue(newValues));
+  }
+
+  return;
+}
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETEventAction.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETEventAction.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETEventAction.cc	(revision 1316)
@@ -0,0 +1,89 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETEventAction.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "AXPETEventAction.hh"
+
+#include "AXPETRunAction.hh"
+
+#include "G4Event.hh"
+#include "G4EventManager.hh"
+#include "G4TrajectoryContainer.hh"
+#include "G4Trajectory.hh"
+#include "G4VVisManager.hh"
+#include "G4ios.hh"
+#include "G4UnitsTable.hh"
+#include "Randomize.hh"
+
+AXPETEventAction::AXPETEventAction(AXPETRunAction* RA)
+ :runaction(RA), verboselevel(1),
+   drawFlag("all"), printModulo(10000)
+{
+  ;
+}
+
+AXPETEventAction::~AXPETEventAction()
+{
+  ;
+}
+
+void AXPETEventAction::BeginOfEventAction(const G4Event* evt)
+{
+  if(verboselevel>1){
+  G4int evtNb = evt->GetEventID();
+
+    if (evtNb%printModulo == 0) {
+    G4cout << "\n---> Begin of Event: " << evtNb << G4endl;
+
+    G4cout << "<<< Event  " << evtNb << " started." << G4endl;
+    }    
+  }
+}
+
+void AXPETEventAction::EndOfEventAction(const G4Event* evt)
+{  
+  
+
+  if(verboselevel>0)
+    G4cout << "<<< Event  " << evt->GetEventID() << " ended." << G4endl;
+ 
+}
+
+G4int AXPETEventAction::GetEventno()
+{
+  G4int evno = fpEventManager->GetConstCurrentEvent()->GetEventID() ;
+  return evno ;
+}
+
+void AXPETEventAction::setEventVerbose(G4int level)
+{
+  verboselevel = level ;
+}
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETMaterial.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETMaterial.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETMaterial.cc	(revision 1316)
@@ -0,0 +1,170 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETMaterial.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "globals.hh"
+#include "G4Material.hh"
+#include "G4MaterialTable.hh"
+#include "G4Element.hh"
+#include "G4ElementTable.hh"
+
+#include "AXPETMaterial.hh"
+
+AXPETMaterial::AXPETMaterial ():
+aluminum(0),matAir(0), LYSO(0), EJ280(0),Vacuum(0)
+{;}
+
+AXPETMaterial::~AXPETMaterial ()
+{
+  delete LYSO;
+  delete EJ280;  
+  delete matAir;  
+  delete Vacuum;  
+}
+
+void AXPETMaterial::DefineMaterials()
+{
+  G4double a; //atomic mass
+  G4double z; //atomic number
+  G4double d; //density
+  G4int nComponents; //number of elements in the material
+
+  a=1.01*g/mole;
+  G4Element* elH = new G4Element("Hydrogen", "H", z=1 , a);
+
+  a = 14.01*g/mole;
+  G4Element* elN = new G4Element("Nitrogen","N",z = 7.,a);
+
+  a = 16.00*g/mole;
+  G4Element* elO = new G4Element("Oxygen","O",z = 8.,a);
+
+  a = 12.011*g/mole;
+  G4Element* elC = new G4Element("Carbon","C",z = 6.,a);
+
+  a = 28.09*g/mole;
+  G4Element* elSi = new G4Element("Silicon", "Si", z = 14., a);
+
+  a = 88.91*g/mole;
+  G4Element* elY = new G4Element("Yttrium", "Y", z = 39., a);
+
+  a = 174.97*g/mole;
+  G4Element* elLu = new G4Element("Lutetium", "Lu", z = 71., a);
+
+
+  //Aluminum
+  aluminum =  new G4Material("Aluminium", z=13., a=26.98*g/mole, d=2.700*g/cm3);
+
+
+  // AIR
+  d = 1.290*mg/cm3;
+  nComponents = 2;
+  G4Material* matAir = new G4Material("AIR", d, nComponents);
+  matAir -> AddElement(elN,0.7);
+  matAir -> AddElement(elO,0.3);
+
+  // LYSO
+  d = 7.1*g/cm3;
+  nComponents=4;
+  LYSO = new G4Material("LYSO", d, nComponents);
+  LYSO->AddElement(elLu,0.72);
+  LYSO->AddElement(elY, 0.04);
+  LYSO->AddElement(elSi,0.06);
+  LYSO->AddElement(elO, 0.18);
+
+  // wls similar to VINYLTOLUENE
+  d=1.02*g/cm3;
+  nComponents = 2;
+  EJ280 = new G4Material("WLSEJ280", d, nComponents);
+  EJ280->AddElement(elH, 0.085);
+  EJ280->AddElement(elC, 0.915);
+
+  Vacuum = new G4Material("Galactic", z=1., a=1.01*g/mole, d = universe_mean_density,
+                           kStateGas, 2.73*kelvin, 3.e-18*pascal);
+
+  // Adding scintillating material properties
+  
+  const G4int nEntries = 11;
+  
+  
+ // G4double PhotonEnergy[nEntries] = {500, 490, 480, 470, 460, 450, 440, 430, 420, 410, 400};
+  G4double PhotonEnergy[nEntries] = {2.478*eV, 2.53*eV, 2.58*eV, 2.636*eV, 2.69*eV, 2.75*eV, 2.816*eV, 2.88*eV, 2.95*eV, 3.022*eV, 3.097*eV};
+
+  // Air properties
+  G4double RIAir[nEntries] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; // Is Isotropic
+  G4MaterialPropertiesTable* MPTAir = new G4MaterialPropertiesTable();
+  MPTAir->AddProperty("RINDEX", PhotonEnergy, RIAir, nEntries);
+  matAir->SetMaterialPropertiesTable(MPTAir);
+  Vacuum->SetMaterialPropertiesTable(MPTAir);
+
+  // LYSO properties
+
+  G4double RILyso[nEntries] = {1.82,1.82,1.82,1.82,1.82,1.82,1.82,1.82,1.82,1.82,1.82};// Is isotropic
+  G4double ABLyso[nEntries] = {100.*cm, 100.*cm, 100.*cm, 100.*cm, 100.*cm, 100.*cm, 100.*cm, 80.* cm, 50. *cm, 30.*cm, 2.*cm}; // To be updated
+  G4double SFLyso[nEntries] = {0., 0., 0., 0., 0., 0., 0.,0.1, 0.8, 0.1, 0.}; // To be updated
+  
+  G4MaterialPropertiesTable* MPTLyso = new G4MaterialPropertiesTable();
+  MPTLyso->AddProperty("RINDEX",        PhotonEnergy, RILyso, nEntries);
+  MPTLyso->AddProperty("ABSLENGTH",     PhotonEnergy, ABLyso, nEntries);
+  MPTLyso->AddProperty("FASTCOMPONENT", PhotonEnergy, SFLyso, nEntries);
+  MPTLyso->AddProperty("SLOWCOMPONENT", PhotonEnergy, SFLyso, nEntries);
+
+  MPTLyso->AddConstProperty("SCINTILLATIONYIELD", 20000./MeV);
+  MPTLyso->AddConstProperty("RESOLUTIONSCALE",    1.04);//R = resolutionscale*sqrt(yield)
+  MPTLyso->AddConstProperty("FASTTIMECONSTANT", 40.*ns);
+  MPTLyso->AddConstProperty("SLOWTIMECONSTANT",10000.*ns);
+  MPTLyso->AddConstProperty("YIELDRATIO",1.0);
+
+  LYSO->SetMaterialPropertiesTable(MPTLyso);
+
+
+  // WLS properties
+
+
+  G4double RIWls[nEntries] = {1.58,1.58,1.58,1.58,1.58,1.58,1.58,1.58,1.58,1.58,1.58}; 
+  G4double ABWls[nEntries] = {200.*mm, 150.*mm, 60.*mm, 30.*mm, 0.5*mm, 0.5*mm, 0.5*mm, 0.5*mm, 0.5*mm, 0.5*mm, 0.5 *mm}; // To be updated
+  G4double EMWls[nEntries] = {0.15,0.6,0.15,0.1,0.,0.,0.,0.,0.,0.,0.}; 
+  
+  G4MaterialPropertiesTable* MPTWls = new G4MaterialPropertiesTable();
+  MPTWls->AddProperty("RINDEX",               PhotonEnergy, RIWls, nEntries);
+  MPTWls->AddProperty("WLSABSLENGTH",         PhotonEnergy, ABWls, nEntries);
+  MPTWls->AddProperty("WLSCOMPONENT",         PhotonEnergy, EMWls, nEntries);
+  MPTWls->AddConstProperty("WLSTIMECONSTANT", 8.5 *ns);
+
+  EJ280->SetMaterialPropertiesTable(MPTWls);
+
+  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
+}
+
+G4Material* AXPETMaterial::GetMat(const G4String& material)
+{
+  G4Material* pttomaterial = G4Material::GetMaterial(material);
+  return pttomaterial;
+}
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPhysicsList.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPhysicsList.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPhysicsList.cc	(revision 1316)
@@ -0,0 +1,255 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETPhysicsList.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "globals.hh"
+#include "AXPETPhysicsList.hh"
+
+#include "G4ParticleDefinition.hh"
+#include "G4ParticleTypes.hh"
+#include "G4ParticleTable.hh"
+
+#include "G4Material.hh"
+#include "G4MaterialTable.hh"
+
+#include "G4ProcessManager.hh"
+#include "G4ProcessVector.hh"
+
+#include "G4Cerenkov.hh"
+#include "G4Scintillation.hh"
+#include "G4OpAbsorption.hh"
+#include "G4OpRayleigh.hh"
+#include "G4OpBoundaryProcess.hh"
+#include "G4OpWLS.hh"
+
+AXPETPhysicsList::AXPETPhysicsList() :  G4VUserPhysicsList()
+{
+  theCerenkovProcess           = 0;
+  theScintillationProcess      = 0;
+  theAbsorptionProcess         = 0;
+  theRayleighScatteringProcess = 0;
+  theBoundaryProcess           = 0;
+  theOpWLSProcess              = 0;
+  
+  SetVerboseLevel(0);
+}
+
+AXPETPhysicsList::~AXPETPhysicsList() 
+{;}
+
+void AXPETPhysicsList::ConstructParticle()
+{
+// Construct bosons
+  // gamma
+  G4Gamma::GammaDefinition();
+
+  // optical photon
+  G4OpticalPhoton::OpticalPhotonDefinition();
+
+// Construct Leptons
+  G4Electron::ElectronDefinition();
+  G4Positron::PositronDefinition();
+  G4NeutrinoE::NeutrinoEDefinition();
+  G4AntiNeutrinoE::AntiNeutrinoEDefinition();
+  G4MuonPlus::MuonPlusDefinition();
+  G4MuonMinus::MuonMinusDefinition();
+  G4NeutrinoMu::NeutrinoMuDefinition();
+  G4AntiNeutrinoMu::AntiNeutrinoMuDefinition();
+
+// Construct mesons
+  G4PionPlus::PionPlusDefinition();
+  G4PionMinus::PionMinusDefinition();
+  G4PionZero::PionZeroDefinition();
+
+  G4cout << "All particles constructed" << G4endl;
+}
+
+
+void AXPETPhysicsList::ConstructProcess()
+{
+  AddTransportation();
+  ConstructGeneral();
+  ConstructEM();
+  ConstructOp();
+}
+
+
+#include "G4Decay.hh"
+
+void AXPETPhysicsList::ConstructGeneral()
+{
+ // Add Decay Process
+  G4Decay* theDecayProcess = new G4Decay();
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    if (theDecayProcess->IsApplicable(*particle)) {
+      pmanager ->AddProcess(theDecayProcess);
+      // set ordering for PostStepDoIt and AtRestDoIt
+      pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep);
+      pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest);
+    }
+  }
+    G4cout << "General processes constructed" << G4endl;
+
+}
+
+
+#include "G4ComptonScattering.hh"
+#include "G4GammaConversion.hh"
+#include "G4PhotoElectricEffect.hh"
+
+#include "G4MultipleScattering.hh"
+
+#include "G4eIonisation.hh"
+#include "G4eBremsstrahlung.hh"
+#include "G4eplusAnnihilation.hh"
+
+#include "G4MuIonisation.hh"
+#include "G4MuBremsstrahlung.hh"
+#include "G4MuPairProduction.hh"
+
+#include "G4hIonisation.hh"
+
+void AXPETPhysicsList::ConstructEM()
+{
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    G4String particleName = particle->GetParticleName();
+
+    if (particleName == "gamma") {
+    // gamma
+      // Construct processes for gamma
+      pmanager->AddDiscreteProcess(new G4GammaConversion());
+      pmanager->AddDiscreteProcess(new G4ComptonScattering());
+      pmanager->AddDiscreteProcess(new G4PhotoElectricEffect());
+
+    } else if (particleName == "e-") {
+    //electron
+      // Construct processes for electron
+      pmanager->AddProcess(new G4MultipleScattering(),-1, 1, 1);
+      pmanager->AddProcess(new G4eIonisation(),       -1, 2, 2);
+      pmanager->AddProcess(new G4eBremsstrahlung(),   -1, 3, 3);
+
+    } else if (particleName == "e+") {
+    //positron
+      // Construct processes for positron
+      pmanager->AddProcess(new G4MultipleScattering(),-1, 1, 1);
+      pmanager->AddProcess(new G4eIonisation(),       -1, 2, 2);
+      pmanager->AddProcess(new G4eBremsstrahlung(),   -1, 3, 3);
+      pmanager->AddProcess(new G4eplusAnnihilation(),  0,-1, 4);
+
+    } else if( particleName == "mu+" ||
+               particleName == "mu-"    ) {
+    //muon
+     // Construct processes for muon
+     pmanager->AddProcess(new G4MultipleScattering(),-1, 1, 1);
+     pmanager->AddProcess(new G4MuIonisation(),      -1, 2, 2);
+     pmanager->AddProcess(new G4MuBremsstrahlung(),  -1, 3, 3);
+     pmanager->AddProcess(new G4MuPairProduction(),  -1, 4, 4);
+
+    } else {
+      if ((particle->GetPDGCharge() != 0.0) &&
+          (particle->GetParticleName() != "chargedgeantino")) {
+     // all others charged particles except geantino
+       pmanager->AddProcess(new G4MultipleScattering(),-1,1,1);
+       pmanager->AddProcess(new G4hIonisation(),       -1,2,2);
+     }
+    }
+  }
+   G4cout << "EM physics constructed" << G4endl;
+
+}
+
+void AXPETPhysicsList::ConstructOp()
+{
+  theCerenkovProcess           = new G4Cerenkov("Cerenkov");
+  theScintillationProcess      = new G4Scintillation("Scintillation");
+  theAbsorptionProcess         = new G4OpAbsorption();
+  theRayleighScatteringProcess = new G4OpRayleigh();
+  theBoundaryProcess           = new G4OpBoundaryProcess();
+  theOpWLSProcess              = new G4OpWLS();
+  
+  theCerenkovProcess->SetTrackSecondariesFirst(true);
+
+  //this is to force the same scintillitation yield for all particle types   
+  theScintillationProcess->SetScintillationYieldFactor(1.);
+  theScintillationProcess->SetTrackSecondariesFirst(true);
+
+//  G4OpticalSurfaceModel themodel = glisur;
+  G4OpticalSurfaceModel themodel = unified;
+  theBoundaryProcess->SetModel(themodel);
+//  theBoundaryProcess->SetVerboseLevel(1);
+
+  // Selects the time profile generator
+   theOpWLSProcess->UseTimeProfile("exponential"); // or ("delta");
+
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    G4String particleName = particle->GetParticleName();
+    if (theCerenkovProcess->IsApplicable(*particle)) {
+      // pmanager->AddContinuousProcess(theCerenkovProcess);
+        pmanager->AddProcess(theCerenkovProcess);
+        pmanager->SetProcessOrdering(theCerenkovProcess,idxPostStep);
+
+    }
+    if (theScintillationProcess->IsApplicable(*particle)) {
+      pmanager->AddProcess(theScintillationProcess);
+      pmanager->SetProcessOrderingToLast(theScintillationProcess, idxAtRest);
+       pmanager->SetProcessOrderingToLast(theScintillationProcess, idxPostStep);
+    }
+    if (particleName == "opticalphoton") {
+      G4cout << " AddDiscreteProcess to OpticalPhoton " << G4endl;
+      pmanager->AddDiscreteProcess(theAbsorptionProcess);
+      pmanager->AddDiscreteProcess(theRayleighScatteringProcess);
+      pmanager->AddDiscreteProcess(theBoundaryProcess);
+      pmanager->AddDiscreteProcess(theOpWLSProcess);
+    }
+  }
+    G4cout << "Optical photon physics constructed" << G4endl;
+
+}
+
+
+void AXPETPhysicsList::SetCuts()
+{
+  //  " G4VUserPhysicsList::SetCutsWithDefault" method sets 
+  //   the default cut value for all particle types
+  // 
+  SetCutsWithDefault();
+  
+  if (verboseLevel>0) DumpCutValuesTable();   
+}
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPrimaryGeneratorAction.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPrimaryGeneratorAction.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPrimaryGeneratorAction.cc	(revision 1316)
@@ -0,0 +1,115 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETPrimaryGeneratorAction.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "AXPETPrimaryGeneratorAction.hh"
+#include "AXPETPrimaryGeneratorMessenger.hh"
+
+#include "Randomize.hh"
+
+#include "G4Event.hh"
+#include "G4ParticleGun.hh"
+#include "G4ParticleTable.hh"
+#include "G4ParticleDefinition.hh"
+
+AXPETPrimaryGeneratorAction::AXPETPrimaryGeneratorAction()
+{
+
+  G4int n_particle = 1;
+  particleGun = new G4ParticleGun(n_particle);
+  
+  //create a messenger for this class
+  gunMessenger = new AXPETPrimaryGeneratorMessenger(this);
+  
+  //default kinematic
+  //
+  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
+  G4ParticleDefinition* particle = particleTable->FindParticle("e-");
+
+  particleGun->SetParticleDefinition(particle);
+  particleGun->SetParticleTime(0.0*ns);
+
+  particleGun->SetParticlePosition(G4ThreeVector(0.0*cm,0.0*mm,15.0*cm));
+  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.));
+  particleGun->SetParticleEnergy(20.0*keV);
+}
+
+AXPETPrimaryGeneratorAction::~AXPETPrimaryGeneratorAction()
+{
+  delete particleGun;
+  delete gunMessenger;
+}
+
+void AXPETPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
+{
+
+  G4double sigma_xy = 10.*mm;//2.5;// ~6 mm (FWHM)
+  G4double x = G4RandGauss::shoot(0.,sigma_xy);
+  G4double y = G4RandGauss::shoot(0.,sigma_xy);
+  G4double z = G4RandGauss::shoot(0.,sigma_xy);//15.0*mm;
+  G4ThreeVector dir;
+  dir=(G4ThreeVector(0,0,0.0*mm)-G4ThreeVector(x,y,z));
+  dir=dir/dir.mag();
+  particleGun->SetParticlePosition(G4ThreeVector(x,y,z));
+  particleGun->SetParticleMomentumDirection(dir);
+  G4cout << x << '\t' << y << '\t' << z << " position [mm] of Primaries" << G4endl;
+  G4cout << dir.x()<<'\t'<<dir.y()<<'\t'<<dir.z()<<'\t' <<" direction of Primaries" << G4endl;
+  particleGun->GeneratePrimaryVertex(anEvent);
+}
+
+void AXPETPrimaryGeneratorAction::SetOptPhotonPolar()
+{
+ G4double angle = G4UniformRand() * 360.0*deg;
+ SetOptPhotonPolar(angle);
+}
+
+void AXPETPrimaryGeneratorAction::SetOptPhotonPolar(G4double angle)
+{
+ if (particleGun->GetParticleDefinition()->GetParticleName() != "opticalphoton")
+   {
+     G4cout << "--> warning from PrimaryGeneratorAction::SetOptPhotonPolar() :"
+               "the particleGun is not an opticalphoton" << G4endl;
+     return;
+   }
+     	       
+ G4ThreeVector normal (1., 0., 0.);
+ G4ThreeVector kphoton = particleGun->GetParticleMomentumDirection();
+ G4ThreeVector product = normal.cross(kphoton); 
+ G4double modul2       = product*product;
+ 
+ G4ThreeVector e_perpend (0., 0., 1.);
+ if (modul2 > 0.) e_perpend = (1./std::sqrt(modul2))*product; 
+ G4ThreeVector e_paralle    = e_perpend.cross(kphoton);
+ 
+ G4ThreeVector polar = std::cos(angle)*e_paralle + std::sin(angle)*e_perpend;
+ particleGun->SetParticlePolarization(polar);
+}
+
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPrimaryGeneratorMessenger.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPrimaryGeneratorMessenger.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPrimaryGeneratorMessenger.cc	(revision 1316)
@@ -0,0 +1,73 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETPrimaryGeneratorMessenger.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "AXPETPrimaryGeneratorMessenger.hh"
+
+#include "AXPETPrimaryGeneratorAction.hh"
+#include "G4UIdirectory.hh"
+#include "G4UIcmdWithADoubleAndUnit.hh"
+
+AXPETPrimaryGeneratorMessenger::AXPETPrimaryGeneratorMessenger(
+                                          AXPETPrimaryGeneratorAction* AXPETGun)
+:AXPETAction(AXPETGun)
+{
+  gunDir = new G4UIdirectory("/AXPET/gun/");
+  gunDir->SetGuidance("PrimaryGenerator control");
+   
+  polarCmd = new G4UIcmdWithADoubleAndUnit("/AXPET/gun/optPhotonPolar",this);
+  polarCmd->SetGuidance("Set linear polarization");
+  polarCmd->SetGuidance("  angle w.r.t. (k,n) plane");
+  polarCmd->SetParameterName("angle",true);
+  polarCmd->SetUnitCategory("Angle");  
+  polarCmd->SetDefaultValue(-360.0);
+  polarCmd->SetDefaultUnit("deg");
+  polarCmd->AvailableForStates(G4State_Idle);
+}
+
+AXPETPrimaryGeneratorMessenger::~AXPETPrimaryGeneratorMessenger()
+{
+  delete polarCmd;
+  delete gunDir;
+}
+
+void AXPETPrimaryGeneratorMessenger::SetNewValue(
+                                        G4UIcommand* command, G4String newValue)
+{ 
+  if( command == polarCmd ) {
+      G4double angle = polarCmd->GetNewDoubleValue(newValue);
+      if ( angle == -360.0*deg ) {
+         AXPETAction->SetOptPhotonPolar();
+      } else {
+         AXPETAction->SetOptPhotonPolar(angle);
+      }
+  }
+}
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETRunAction.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETRunAction.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETRunAction.cc	(revision 1316)
@@ -0,0 +1,69 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETRunAction.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "G4Timer.hh"
+
+#include "G4RunManager.hh"
+#include "AXPETRunAction.hh"
+
+#include "G4Run.hh"
+
+
+AXPETRunAction::AXPETRunAction(): 
+energylyso(0), timelyso(-1), lyso(-1)
+{
+  timer = new G4Timer;
+}
+
+
+AXPETRunAction::~AXPETRunAction()
+{
+  delete timer;
+}
+
+
+void AXPETRunAction::BeginOfRunAction(const G4Run* aRun)
+{
+   G4RunManager::GetRunManager()->SetRandomNumberStore(true);
+   G4cout << "Run " << aRun -> GetRunID() << " starts ..." << G4endl;
+   runID = aRun->GetRunID();
+
+   timer->Start();
+}
+
+
+void AXPETRunAction::EndOfRunAction(const G4Run* aRun)
+{
+  timer->Stop();
+  G4cout << "number of event = " << aRun->GetNumberOfEvent() 
+         << " " << *timer << G4endl;	 
+}
Index: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETSteppingAction.cc
===================================================================
--- trunk/source/geometry/solids/test/OpticalEscape/src/AXPETSteppingAction.cc	(revision 1316)
+++ trunk/source/geometry/solids/test/OpticalEscape/src/AXPETSteppingAction.cc	(revision 1316)
@@ -0,0 +1,142 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: AXPETSteppingAction.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
+// ------------------------------------------------------------
+// Geant4 class implementation file
+//
+// 03/09/2008, by T.Nikitina
+// ------------------------------------------------------------
+
+#include "G4SteppingManager.hh"
+#include "G4TrackVector.hh"
+
+#include "AXPETSteppingAction.hh"
+
+#include "AXPETDetectorConstruction.hh"
+#include "AXPETRunAction.hh"
+
+#include "G4Track.hh"
+#include "G4Event.hh"
+#include "G4EventManager.hh"
+#include "G4ParticleDefinition.hh"
+#include "G4ProcessManager.hh"
+#include "G4OpBoundaryProcess.hh"
+#include "G4ios.hh"
+#include <iomanip>
+#include "G4UImanager.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4VSolid.hh"
+#include "G4RotationMatrix.hh"
+#include "G4AffineTransform.hh"
+AXPETSteppingAction::AXPETSteppingAction(AXPETDetectorConstruction* DET,
+                                         AXPETRunAction* RA)
+:detector (DET), runaction (RA)
+{
+
+  G4cout << "Costructor of the Stepping Action class " << G4endl;
+  
+}
+
+
+AXPETSteppingAction::~AXPETSteppingAction()
+{;}
+
+
+void AXPETSteppingAction::UserSteppingAction(const G4Step* aStep)
+{
+
+  // track informations
+  //
+  // const G4StepPoint* prePoint = aStep->GetPreStepPoint();   
+  const G4StepPoint* endPoint = aStep->GetPostStepPoint();
+  const G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition(); 
+
+  G4String partName  = particle->GetParticleName();
+  G4VPhysicalVolume* postVolume_phys=endPoint->GetPhysicalVolume();
+  G4String solidName=" out of Crystal ";
+  if(postVolume_phys)    // Reach to out of the world
+  solidName = postVolume_phys->GetLogicalVolume()->GetSolid()->GetName();
+  //Detect optical photons going outside Volume
+
+  if(partName=="opticalphoton")
+  {
+    // Additional Printing on each Step
+    //
+    // G4cout<<aStep->GetTrack()->GetCurrentStepNumber()<<" StartPoint="<<prePoint->GetPosition()
+    // <<" EndPoint="<<endPoint->GetPosition()<<" NextSolid= "<<solidName<<G4endl;
+    // G4cout<<aStep->GetTrack()->GetCurrentStepNumber()<<" StartDirection="<<prePoint->GetMomentumDirection()
+    // <<" EndDirection="<<endPoint->GetMomentumDirection()<<" NextSolid= "<<solidName<<G4endl;
+    G4double x=endPoint->GetPosition().x()/mm;
+    G4double y=endPoint->GetPosition().y()/mm;
+    //
+    // Condition to detect Escaping Optical Photon: 
+    //
+    if(std::sqrt(x*x+y*y)>(detector->GetExtend()*2.)){
+      G4cerr.precision(16);
+      G4cerr << "ERROR - UserSteppingAction::OpticalPhoton is out of Crystal Solid" << G4endl
+	     <<" Wrong Point is "<<xStep<<"  "<<yStep<<"  "<<zStep << G4endl
+             <<" Wrong Direction is "<<xDirection<<"  "<<yDirection<<"  "<<zDirection<< G4endl;
+      G4VSolid *solid=detector->GetSolid();
+      G4ThreeVector point = G4ThreeVector(xStep,yStep,zStep);
+      G4ThreeVector dir = G4ThreeVector(xDirection,yDirection,zDirection); 
+        G4ThreeVector norm,*pNorm;
+        G4bool *pgoodNorm, goodNorm, calcNorm=true;
+        pNorm=&norm;
+        pgoodNorm=&goodNorm;
+
+       EInside surface=solid->Inside(point);
+       if(surface == kInside){
+	 G4cout<<"WrongPoint is Inside DistanceToOut="<<solid->DistanceToOut(point,dir,calcNorm,pgoodNorm,pNorm)<<" Norm(DistToOut)="<<norm<<G4endl;
+       }
+       else if(surface == kOutside){
+       G4cout<<"WrongPoint is Outside DistanceToIn(p,+v)="<<solid->DistanceToIn(point,dir)<<G4endl;
+       G4cout<<"                      DistanceToIn(p,-v)="<<solid->DistanceToIn(point,-dir)<<G4endl;
+       }
+       else{
+       G4cout<<"WrongPoint is On Surface DistanceToIn(p,+v)="<<solid->DistanceToIn(point,dir)<<G4endl;
+       G4cout<<"                         DistanceToIn(p,-v)="<<solid->DistanceToIn(point,-dir)<<G4endl;
+       G4cout<<"                         DistanceToOut="<<solid->DistanceToOut(point,dir,calcNorm,pgoodNorm,pNorm)<<" Norm(DistanceToOut)="<<norm<<G4endl;
+       G4cout<<"                         SurfaceNormal=="<<solid->SurfaceNormal(point)<<G4endl;
+       }
+       if(detector->GetAbortAction()){
+       G4Exception( "  ", "Escaping Optical Photon",
+                  FatalException, "Optical Photon outside Crystal" );
+       }
+       else{
+       G4Exception( "  ", "Escaping Optical Photon",
+                  JustWarning, "Optical Photon outside Crystal" );
+       }
+    }
+    // Save values of Step
+   
+    xStep=x;
+    yStep=y;
+    zStep=endPoint->GetPosition().z()/mm;
+    xDirection=endPoint->GetMomentumDirection().x();
+    yDirection=endPoint->GetMomentumDirection().y();
+    zDirection=endPoint->GetMomentumDirection().z();
+  }
+}
