// This code implementation is the intellectual property of
// the GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4PhotoElectricEffect.icc,v 1.2.8.1 1999/12/07 20:50:51 gunter Exp $
// GEANT4 tag $Name: geant4-01-00 $
//
// 
// ---------------------------------------------------------------
//      GEANT 4 class inlined methods file
//
//      For information related to this code contact:
//      CERN, CN Division, ASD group
//      History: first implementation, based on object model of
//      2nd December 1995, G.Cosmo
//      ------------ G4PhotoElectricEffect physics process ---------
//                   by Michel Maire, April 1996
// ***************************************************************
// 12-06-96, update by M.Maire
// 17-09-96, PartialSumSigma(i)
//           split ComputeBinbingEnergy(), M.Maire
// 08-01-97, crossection table + meanfreepath table , M.Maire
// 13-03-97, adapted for the new physics scheme, M.Maire
// 20-11-97, change for lowest energy limit default action
// 17-11-98, use table of atomic shells in PostStepDoIt, mma
// 06-01-99, use Sandia crossSection, V.Grichine mma
// ---------------------------------------------------------------

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

inline G4bool G4PhotoElectricEffect::IsApplicable(const G4ParticleDefinition& particle)
{
   return ( &particle == G4Gamma::Gamma() ); 
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

inline G4double G4PhotoElectricEffect::GetCrossSectionPerAtom(
                                     const G4DynamicParticle* aDynamicGamma,
                                           G4Element* anElement)
 
// gives the microscopic total cross section in GEANT4 internal units

{
   G4double crossSection;
   G4double GammaEnergy  = aDynamicGamma->GetKineticEnergy();
   G4double AtomicNumber = anElement->GetZ();
   G4bool isOutRange;

   if (GammaEnergy > HighestEnergyLimit) 
     crossSection = 0.;
   else if (GammaEnergy > LowestEnergyLimit)
     crossSection = (*theCrossSectionTable)(anElement->GetIndex())->
                                       GetValue(GammaEnergy, isOutRange);
   else
     crossSection = ComputeSandiaCrossSection(GammaEnergy,AtomicNumber);     

   return crossSection;
} 

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

inline G4double G4PhotoElectricEffect::GetMeanFreePath(const G4Track& aTrack,
                                                       G4double,
                                                       G4ForceCondition*)


// returns the gamma mean free path in GEANT4 internal units
// ( MeanFreePath is a private data member of the class)

{
   const G4DynamicParticle* aDynamicGamma = aTrack.GetDynamicParticle();
   G4double GammaEnergy = aDynamicGamma->GetKineticEnergy();
   G4Material* aMaterial = aTrack.GetMaterial();

   G4bool isOutRange ;

   if (GammaEnergy > HighestEnergyLimit)
     MeanFreePath = DBL_MAX;
   else if (GammaEnergy > LowestEnergyLimit) 
     MeanFreePath = (*theMeanFreePathTable)(aMaterial->GetIndex())->
                                       GetValue(GammaEnergy, isOutRange); 
   else
     MeanFreePath = ComputeSandiaMeanFreePath(GammaEnergy, aMaterial);   

   return MeanFreePath;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

inline G4double G4PhotoElectricEffect::ComputeMeanFreePath(G4double GammaEnergy,
                                                           G4Material* aMaterial)

// returns the gamma mean free path in GEANT4 internal units

{
  const G4ElementVector* theElementVector = aMaterial->GetElementVector() ;
  const G4double*      NbOfAtomsPerVolume = aMaterial->GetVecNbOfAtomsPerVolume();   

  G4double SIGMA = 0 ;

  for ( G4int elm=0 ; elm < aMaterial->GetNumberOfElements() ; elm++ )
      {             
            SIGMA += NbOfAtomsPerVolume[elm] * 
                     ComputeCrossSectionPerAtom(GammaEnergy,
                                             (*theElementVector)(elm)->GetZ());
      }       

  return SIGMA > DBL_MIN ? 1./SIGMA : DBL_MAX ;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
                                                         
inline 
G4double G4PhotoElectricEffect::ComputeSandiaMeanFreePath(G4double GammaEnergy,
                                                          G4Material* aMaterial)
{
  G4double energy2 = GammaEnergy*GammaEnergy, energy3 = GammaEnergy*energy2, 
           energy4 = energy2*energy2;

  G4double* SandiaCof = aMaterial->GetSandiaTable()
                                 ->GetSandiaCofForMaterial(GammaEnergy);

  G4double SIGMA = SandiaCof[0]/GammaEnergy + SandiaCof[1]/energy2 +
	           SandiaCof[2]/energy3     + SandiaCof[3]/energy4; 
          
  return SIGMA > DBL_MIN ? 1./SIGMA : DBL_MAX ;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 
inline G4double G4PhotoElectricEffect::ComputeKBindingEnergy (G4double Z)
 
// Calculates the binding energy of the K electronic shell, as a function
// of the Atomic Number, from a parametrized formula of L. Urban.

{
  const G4double
  aK (6.6644*eV), bK (2.2077e-1*eV), cK (-3.2552e-3*eV), dK (1.8199e-5*eV);

  return Z*Z*(aK  + Z* (bK + Z* (cK + Z* dK))); 
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

inline G4double G4PhotoElectricEffect::ComputeL1BindingEnergy (G4double Z)
 
// Calculates the binding energy of the L1 electronic shell, as a function
// of the Atomic Number, from a parametrized formula of L. Urban.

{
  const G4double
  aL1(-2.9179e-1*eV), bL1(8.7983e-2*eV), cL1(-1.2589e-3*eV), dL1(6.9602e-6*eV);
  
  return Z*Z*(aL1 + Z* (bL1 + Z* (cL1 + Z* dL1)));
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

inline G4double G4PhotoElectricEffect::ComputeL2BindingEnergy (G4double Z)
 
// Calculates the binding energy of the L2 electronic shell, as a function
// of the Atomic Number, from a parametrized formula of L. Urban.

{
  const G4double
  aL2(-6.8606e-1*eV), bL2(1.0078e-1*eV), cL2(-1.4496e-3*eV), dL2(7.8809e-6*eV);

  return Z*Z*(aL2 + Z* (bL2 + Z* (cL2 + Z* dL2)));
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....


