Index: trunk/source/processes/optical/History
===================================================================
--- trunk/source/processes/optical/History	(revision 819)
+++ trunk/source/processes/optical/History	(revision 963)
@@ -16,4 +16,47 @@
      * Reverse chronological order (last date on top), please *
      ----------------------------------------------------------
+
+14th Jan 2009 Peter Gumplinger (op-V09-02-00)
+              respond to bug report 1040 by fixing G4OpBoundaryProcess.cc 
+
+07th Nov 2008 Peter Gumplinger (op-V09-01-09)
+              use new global/HEPRandom's G4RandomTools.hh
+
+24th Oct 2008 Peter Gumplinger (op-V09-01-08)
+              use local G4OpProcessSubType.hh
+
+21st Oct 2008 Peter Gumplinger (op-V09-01-07)
+              add SetProcessSubType for G4OpAbsorption, G4OpBoundaryProcess,
+              G4OpRayleigh and G4OpWLS
+
+18th Aug 2008 Peter Gumplinger (op-V09-01-06)
+              use signatures G4SwapPtr(T*& and G4SwapObj(T*
+              in G4OpBoundaryProcess - to work with global-V09-01-12
+
+15th Aug 2008 Peter Gumplinger (op-V09-01-05)
+              replaced G4SwapPtr with G4SwapObj for Rindex
+              in G4OpBoundaryProcess - serious error since op-V09-01-00
+              (see also Problem Report 1020)
+
+4th July 2008 Peter Gumplinger (op-V09-01-04)
+              In G4OpWLS now SetTouchableHandle(aTrack.GetTouchableHandle())
+              for the secondaries in the DoIt.
+              In G4OpBoundaryProcess.cc initialize the pointer:
+              G4LogicalSurface* Surface = NULL;
+
+27th June 2008 Peter Gumplinger (op-V09-01-03)
+               In G4OpBoundaryProcess changed unsafe cast
+               (G4OpticalSurface*) to dynamic_cast<G4OpticalSurface*>
+               following suggestion in bug-report #1014
+
+6th June 2008 Peter Gumplinger (op-V09-01-02)
+              G4OpRayleigh, G4OpWLS = trivial name changes: 
+              momentum->energy, momenta->energies
+
+5th June 2008 Peter Gumplinger (op-V09-01-00)
+              G4OpBoundaryProcess: Removed G4Swap methods - replaced by
+              G4SwapPtr. Removed G4IsotropicRand method - replaced by
+              G4RandomDirection. Add commented code to change absorption
+              at a dielectric/metal boundary into transmission.
 
 29th Oct 2007 Peter Gumplinger (op-V09-00-01)
Index: trunk/source/processes/optical/include/G4OpAbsorption.hh
===================================================================
--- trunk/source/processes/optical/include/G4OpAbsorption.hh	(revision 819)
+++ trunk/source/processes/optical/include/G4OpAbsorption.hh	(revision 963)
@@ -26,5 +26,5 @@
 //
 // $Id: G4OpAbsorption.hh,v 1.9 2006/06/29 21:08:36 gunter Exp $
-// GEANT4 tag $Name:  $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 ////////////////////////////////////////////////////////////////////////
Index: trunk/source/processes/optical/include/G4OpBoundaryProcess.hh
===================================================================
--- trunk/source/processes/optical/include/G4OpBoundaryProcess.hh	(revision 819)
+++ trunk/source/processes/optical/include/G4OpBoundaryProcess.hh	(revision 963)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4OpBoundaryProcess.hh,v 1.16 2007/10/15 21:16:24 gum Exp $
-// GEANT4 tag $Name:  $
+// $Id: G4OpBoundaryProcess.hh,v 1.18 2008/11/07 17:59:37 gum Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // 
@@ -68,4 +68,8 @@
 #include "geomdefs.hh"
 #include "Randomize.hh"
+
+#include "G4RandomTools.hh"
+#include "G4RandomDirection.hh"
+
 #include "G4Step.hh"
 #include "G4VDiscreteProcess.hh"
@@ -162,17 +166,5 @@
 private:
 
-	void G4Swap(G4double* a, G4double* b) const;
-
-	void G4Swap(G4Material* a, G4Material* b) const;
-
-	void G4VectorSwap(G4ThreeVector* vec1, G4ThreeVector* vec2) const;
-
 	G4bool G4BooleanRand(const G4double prob) const;
-
-	G4ThreeVector G4IsotropicRand() const;
-
-	G4ThreeVector G4LambertianRand(const G4ThreeVector& normal);
-
-	G4ThreeVector G4PlaneVectorRand(const G4ThreeVector& normal) const;
 
 	G4ThreeVector GetFacetNormal(const G4ThreeVector& Momentum,
@@ -229,43 +221,4 @@
 
 inline
-void G4OpBoundaryProcess::G4Swap(G4double* a, G4double* b) const
-{
-	// swaps the contents of the objects pointed
-	// to by 'a' and 'b'!
-
-  G4double temp;
-
-  temp = *a;
-  *a = *b;
-  *b = temp;
-}
-
-inline
-void G4OpBoundaryProcess::G4Swap(G4Material* a, G4Material* b) const
-{
-	// ONLY swaps the pointers; i.e. what used to be pointed
-	// to by 'a' is now pointed to by 'b' and vice versa!
-
-   G4Material* temp = a;
-
-   a = b;
-   b = temp;
-}
-
-inline
-void G4OpBoundaryProcess::G4VectorSwap(G4ThreeVector* vec1,
-				       G4ThreeVector* vec2) const
-{
-        // swaps the contents of the objects pointed
-        // to by 'vec1' and 'vec2'!
-
-  G4ThreeVector temp;
-
-  temp = *vec1;
-  *vec1 = *vec2;
-  *vec2 = temp;
-}
-
-inline
 G4bool G4OpBoundaryProcess::G4BooleanRand(const G4double prob) const
 {
@@ -273,66 +226,4 @@
 
   return (G4UniformRand() < prob);
-}
-
-inline
-G4ThreeVector G4OpBoundaryProcess::G4IsotropicRand() const
-{
-  /* Returns a random isotropic unit vector. */
-
-  G4ThreeVector vect;
-  G4double len2;
-
-  do {
-
-    vect.setX(G4UniformRand() - 0.5);
-    vect.setY(G4UniformRand() - 0.5);
-    vect.setZ(G4UniformRand() - 0.5);
-
-    len2 = vect.mag2();
-
-  } while (len2 < 0.01 || len2 > 0.25);
-
-  return vect.unit();
-}
-
-inline
-G4ThreeVector G4OpBoundaryProcess::
-	      G4LambertianRand(const G4ThreeVector& normal)
-{
-  /* Returns a random lambertian unit vector. */
-
-  G4ThreeVector vect;
-  G4double ndotv;
-
-  do {
-    vect = G4IsotropicRand();
-
-    ndotv = normal * vect;
-
-    if (ndotv < 0.0) {
-      vect = -vect;
-      ndotv = -ndotv;
-    }
-
-  } while (!G4BooleanRand(ndotv));
-  return vect;
-}
-
-inline
-G4ThreeVector G4OpBoundaryProcess::
-	      G4PlaneVectorRand(const G4ThreeVector& normal) const
-
-  /* This function chooses a random vector within a plane given
-     by the unit normal */
-{
-  G4ThreeVector vec1 = normal.orthogonal();
-
-  G4ThreeVector vec2 = vec1.cross(normal);
-
-  G4double phi = twopi*G4UniformRand();
-  G4double cosphi = std::cos(phi);
-  G4double sinphi = std::sin(phi);
-
-  return cosphi * vec1 + sinphi * vec2;
 }
 
Index: trunk/source/processes/optical/include/G4OpRayleigh.hh
===================================================================
--- trunk/source/processes/optical/include/G4OpRayleigh.hh	(revision 819)
+++ trunk/source/processes/optical/include/G4OpRayleigh.hh	(revision 963)
@@ -26,5 +26,5 @@
 //
 // $Id: G4OpRayleigh.hh,v 1.9 2006/06/29 21:08:40 gunter Exp $
-// GEANT4 tag $Name:  $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // 
Index: trunk/source/processes/optical/include/G4OpWLS.hh
===================================================================
--- trunk/source/processes/optical/include/G4OpWLS.hh	(revision 819)
+++ trunk/source/processes/optical/include/G4OpWLS.hh	(revision 963)
@@ -26,5 +26,5 @@
 //
 // $Id: G4OpWLS.hh,v 1.4 2006/06/29 21:08:42 gunter Exp $
-// GEANT4 tag $Name:  $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 ////////////////////////////////////////////////////////////////////////
Index: trunk/source/processes/optical/src/G4OpAbsorption.cc
===================================================================
--- trunk/source/processes/optical/src/G4OpAbsorption.cc	(revision 819)
+++ trunk/source/processes/optical/src/G4OpAbsorption.cc	(revision 963)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4OpAbsorption.cc,v 1.7 2006/06/29 21:08:50 gunter Exp $
-// GEANT4 tag $Name:  $
+// $Id: G4OpAbsorption.cc,v 1.9 2008/10/24 19:52:28 gum Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -52,4 +52,6 @@
 
 #include "G4ios.hh"
+#include "G4OpProcessSubType.hh"
+
 #include "G4OpAbsorption.hh"
 
@@ -76,4 +78,6 @@
            G4cout << GetProcessName() << " is created " << G4endl;
         }
+
+        SetProcessSubType(fOpAbsorption);
 }
 
Index: trunk/source/processes/optical/src/G4OpBoundaryProcess.cc
===================================================================
--- trunk/source/processes/optical/src/G4OpBoundaryProcess.cc	(revision 819)
+++ trunk/source/processes/optical/src/G4OpBoundaryProcess.cc	(revision 963)
@@ -67,4 +67,6 @@
 
 #include "G4ios.hh"
+#include "G4OpProcessSubType.hh"
+
 #include "G4OpBoundaryProcess.hh"
 #include "G4GeometryTolerance.hh"
@@ -93,4 +95,6 @@
            G4cout << GetProcessName() << " is created " << G4endl;
         }
+
+        SetProcessSubType(fOpBoundary);
 
 	theStatus = Undefined;
@@ -220,7 +224,9 @@
         OpticalSurface = NULL;
 
-        G4LogicalSurface* Surface = G4LogicalBorderSurface::GetSurface
-				    (pPreStepPoint ->GetPhysicalVolume(),
-				     pPostStepPoint->GetPhysicalVolume());
+        G4LogicalSurface* Surface = NULL;
+
+        Surface = G4LogicalBorderSurface::GetSurface
+	          (pPreStepPoint ->GetPhysicalVolume(),
+	           pPostStepPoint->GetPhysicalVolume());
 
         if (Surface == NULL){
@@ -249,6 +255,6 @@
 	}
 
-	//	if (Surface) OpticalSurface = dynamic_cast <G4OpticalSurface*> (Surface->GetSurfaceProperty());
-	if (Surface) OpticalSurface = (G4OpticalSurface*) Surface->GetSurfaceProperty();
+	if (Surface) OpticalSurface = 
+           dynamic_cast <G4OpticalSurface*> (Surface->GetSurfaceProperty());
 
 	if (OpticalSurface) {
@@ -429,4 +435,10 @@
 
 	  DielectricMetal();
+
+          // Uncomment the following lines if you wish to have 
+          //         Transmission instead of Absorption
+          // if (theStatus == Absorption) {
+          //    return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
+          // }
 
 	}
@@ -579,5 +591,9 @@
            if( !G4BooleanRand(theReflectivity) && n == 1 ) {
 
+             // Comment out DoAbsorption and uncomment theStatus = Absorption;
+             // if you wish to have Transmission instead of Absorption
+
              DoAbsorption();
+             // theStatus = Absorption;
              break;
 
@@ -657,6 +673,6 @@
 	      Through = false;
 	      theGlobalNormal = -theGlobalNormal;
-	      G4Swap(Material1,Material2);
-	      G4Swap(&Rindex1,&Rindex2);
+	      G4SwapPtr(Material1,Material2);
+	      G4SwapObj(&Rindex1,&Rindex2);
 	   }
 
@@ -864,6 +880,6 @@
 	        else {
 		   Swap = !Swap;
-		   G4Swap(Material1,Material2);
-		   G4Swap(&Rindex1,&Rindex2);
+		   G4SwapPtr(Material1,Material2);
+		   G4SwapObj(&Rindex1,&Rindex2);
 	        }
 		if ( theFinish == groundbackpainted )
Index: trunk/source/processes/optical/src/G4OpRayleigh.cc
===================================================================
--- trunk/source/processes/optical/src/G4OpRayleigh.cc	(revision 819)
+++ trunk/source/processes/optical/src/G4OpRayleigh.cc	(revision 963)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4OpRayleigh.cc,v 1.14 2006/06/29 21:08:54 gunter Exp $
-// GEANT4 tag $Name:  $
+// $Id: G4OpRayleigh.cc,v 1.17 2008/10/24 19:51:12 gum Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // 
@@ -57,4 +57,6 @@
 
 #include "G4ios.hh"
+#include "G4OpProcessSubType.hh"
+
 #include "G4OpRayleigh.hh"
 
@@ -78,4 +80,5 @@
            : G4VDiscreteProcess(processName, type)
 {
+        SetProcessSubType(fOpRayleigh);
 
         thePhysicsTable = 0;
@@ -248,5 +251,5 @@
         const G4Material* aMaterial = aTrack.GetMaterial();
 
-        G4double thePhotonMomentum = aParticle->GetTotalMomentum();
+        G4double thePhotonEnergy = aParticle->GetTotalEnergy();
 
         G4double AttenuationLength = DBL_MAX;
@@ -258,5 +261,5 @@
            AttenuationLength =
                 (*thePhysicsTable)(aMaterial->GetIndex())->
-                           GetValue(thePhotonMomentum, isOutRange);
+                           GetValue(thePhotonEnergy, isOutRange);
         }
         else {
@@ -270,5 +273,5 @@
              if(AttenuationLengthVector){
                AttenuationLength = AttenuationLengthVector ->
-                                    GetProperty(thePhotonMomentum);
+                                    GetProperty(thePhotonEnergy);
              }
              else{
@@ -305,5 +308,5 @@
 
         // Retrieve vectors for refraction index
-        // and photon momentum from the material properties table
+        // and photon energy from the material properties table
 
         G4MaterialPropertyVector* Rindex = aMPT->GetProperty("RINDEX");
@@ -325,5 +328,5 @@
            while (++(*Rindex)) {
 
-                e = (Rindex->GetPhotonMomentum());
+                e = (Rindex->GetPhotonEnergy());
 
                 refraction_index = Rindex->GetProperty();
@@ -332,5 +335,5 @@
 
 	        if (verboseLevel>0) {
-        	        G4cout << Rindex->GetPhotonMomentum() << " MeV\t";
+        	        G4cout << Rindex->GetPhotonEnergy() << " MeV\t";
                 	G4cout << xlambda << " mm\t";
 		}
@@ -347,5 +350,5 @@
 		}
                 RayleighScatteringLengths->
-			InsertValues(Rindex->GetPhotonMomentum(), Dist);
+			InsertValues(Rindex->GetPhotonEnergy(), Dist);
            }
 
Index: trunk/source/processes/optical/src/G4OpWLS.cc
===================================================================
--- trunk/source/processes/optical/src/G4OpWLS.cc	(revision 819)
+++ trunk/source/processes/optical/src/G4OpWLS.cc	(revision 963)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4OpWLS.cc,v 1.9 2007/10/30 03:53:36 gum Exp $
-// GEANT4 tag $Name:  $
+// $Id: G4OpWLS.cc,v 1.13 2008/10/24 19:50:50 gum Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -46,4 +46,6 @@
 
 #include "G4ios.hh"
+#include "G4OpProcessSubType.hh"
+
 #include "G4OpWLS.hh"
 #include "G4WLSTimeGeneratorProfileDelta.hh"
@@ -61,4 +63,6 @@
   : G4VDiscreteProcess(processName, type)
 {
+  SetProcessSubType(fOpWLS);
+
   theIntegralTable = 0;
  
@@ -161,12 +165,12 @@
   for (G4int i = 0; i < NumPhotons; i++) {
     
-    // Determine photon momentum
+    // Determine photon energy
     
     G4double CIIvalue = G4UniformRand()*CIImax;
-    G4double sampledMomentum = 
+    G4double sampledEnergy = 
       WLSIntegral->GetEnergy(CIIvalue);
     
     if (verboseLevel>1) {
-      G4cout << "sampledMomentum = " << sampledMomentum << G4endl;
+      G4cout << "sampledEnergy = " << sampledEnergy << G4endl;
       G4cout << "CIIvalue =        " << CIIvalue << G4endl;
     }
@@ -217,5 +221,5 @@
        photonPolarization.z());
     
-    aWLSPhoton->SetKineticEnergy(sampledMomentum);
+    aWLSPhoton->SetKineticEnergy(sampledEnergy);
     
     // Generate new G4Track object:
@@ -230,6 +234,7 @@
     G4Track* aSecondaryTrack = 
       new G4Track(aWLSPhoton,aSecondaryTime,aSecondaryPosition);
-    
-    aSecondaryTrack->SetTouchableHandle((G4VTouchable*)0);
+   
+    aSecondaryTrack->SetTouchableHandle(aTrack.GetTouchableHandle()); 
+    // aSecondaryTrack->SetTouchableHandle((G4VTouchable*)0);
     
     aSecondaryTrack->SetParentID(aTrack.GetTrackID());
@@ -285,5 +290,5 @@
 	  
 	  // Retrieve the first intensity point in vector
-	  // of (photon momentum, intensity) pairs
+	  // of (photon energy, intensity) pairs
 	  
 	  theWLSVector->ResetIterator();
@@ -295,8 +300,8 @@
 	  if (currentIN >= 0.0) {
 
-	    // Create first (photon momentum) 
+	    // Create first (photon energy) 
 	   
 	    G4double currentPM = theWLSVector->
-	      GetPhotonMomentum();
+	      GetPhotonEnergy();
 	    
 	    G4double currentCII = 0.0;
@@ -311,5 +316,5 @@
 	    G4double prevIN  = currentIN;
 	    
-	    // loop over all (photon momentum, intensity)
+	    // loop over all (photon energy, intensity)
 	    // pairs stored for this material
 	    
@@ -317,5 +322,5 @@
 	      {
 		currentPM = theWLSVector->
-		  GetPhotonMomentum();
+		  GetPhotonEnergy();
 		
 		currentIN=theWLSVector->
@@ -355,5 +360,5 @@
   const G4Material* aMaterial = aTrack.GetMaterial();
 
-  G4double thePhotonMomentum = aParticle->GetTotalMomentum();
+  G4double thePhotonEnergy = aParticle->GetTotalEnergy();
 
   G4MaterialPropertiesTable* aMaterialPropertyTable;
@@ -369,5 +374,5 @@
     if ( AttenuationLengthVector ){
       AttenuationLength = AttenuationLengthVector->
-	GetProperty (thePhotonMomentum);
+	GetProperty (thePhotonEnergy);
     }
     else {
