// 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: G4eBremsstrahlungPlus.icc,v 1.1.10.1 1999/12/07 20:50:52 gunter Exp $
// GEANT4 tag $Name: geant4-01-00 $
//
// 
// ---------------------------------------------------------------
//      GEANT 4 class inlined methods file
//
//      For information related to this code contact:
//      CERN, IT Division, ASD group
//      History: first implementation, based on object model of
//      2nd December 1995, G.Cosmo
//      ------------ G4eBremsstrahlungPlus physics process ---------
//                     by Michel Maire, 27 July 1996
// ***************************************************************
// 13-12-96 : Sign corrected in the ScreenFunctions, L.Urban
// 20/03/97 : new energy loss+ionisation+brems scheme, L.Urban
// ***************************************************************

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

inline G4bool G4eBremsstrahlungPlus::IsApplicable(
                            const G4ParticleDefinition& particle)
{
   return(  (&particle == G4Electron::Electron())
          ||(&particle == G4Positron::Positron()) );
}

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

inline G4double G4eBremsstrahlungPlus::GetMeanFreePath(const G4Track& track,
                                                         G4double,
                                                         G4ForceCondition*)
 
// gives the MeanFreePath in GEANT4 internal units

{
   const G4DynamicParticle* aDynamicParticle = track.GetDynamicParticle();
   G4double KineticEnergy = aDynamicParticle->GetKineticEnergy();
   G4Material* aMaterial  = track.GetMaterial();
   
   G4double MeanFreePath;
   G4bool isOutRange ;

   if (KineticEnergy <  LowestKineticEnergy)
     MeanFreePath = DBL_MAX;
   else {
     if (KineticEnergy > HighestKineticEnergy) KineticEnergy = 0.99*HighestKineticEnergy ;
     MeanFreePath = (*theMeanFreePathTable)(aMaterial->GetIndex())->
                    GetValue( KineticEnergy, isOutRange );
   }

   return MeanFreePath; 
} 

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

inline G4double G4eBremsstrahlungPlus::ScreenFunction1(G4double ScreenVariable)

// compute the value of the screening function 3*PHI1 - PHI2

{
   G4double screenVal;

   if (ScreenVariable > 1.)
     screenVal = 42.24 - 8.368*log(ScreenVariable+0.952);
   else
     screenVal = 42.392 - ScreenVariable* (7.796 - 1.961*ScreenVariable);

   return screenVal;
} 

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

inline G4double G4eBremsstrahlungPlus::ScreenFunction2(G4double ScreenVariable)

// compute the value of the screening function 1.5*PHI1 - 0.5*PHI2

{
   G4double screenVal;

   if (ScreenVariable > 1.)
     screenVal = 42.24 - 8.368*log(ScreenVariable+0.952);
   else
     screenVal = 41.734 - ScreenVariable* (6.484 - 1.250*ScreenVariable);

   return screenVal;
} 

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

inline G4double G4eBremsstrahlungPlus::ComputeMeanFreePath(
                                     const G4ParticleDefinition* ParticleType,
                                           G4double KineticEnergy,
                                           const G4Material* aMaterial)
{
  const G4ElementVector* theElementVector = aMaterial->GetElementVector() ;
  const G4double* theAtomNumDensityVector = aMaterial->GetAtomicNumDensityVector();
  G4double GammaEnergyCut = (G4Gamma::GetCutsInEnergy())[aMaterial->GetIndex()];   
  G4double SIGMA = 0 ;

  for ( G4int i=0 ; i < aMaterial->GetNumberOfElements() ; i++ )
      {             
            SIGMA += theAtomNumDensityVector[i] * 
                     ComputeMicroscopicCrossSection( ParticleType, KineticEnergy,
                                                     (*theElementVector)(i)->GetZ(), 
                                                     GammaEnergyCut );
      }       

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

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

inline G4double G4eBremsstrahlungPlus::GetLambda(
                              G4double KineticEnergy,
                              G4Material* material)
{
  G4bool isOut;
  const G4MaterialTable* theMaterialTable =
                       G4Material::GetMaterialTable() ;
 
  G4double lambda = (*theMeanFreePathTable)
                    [material->GetIndex()]->
                    GetValue(KineticEnergy,isOut);
  return lambda;
}


