Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-13 08:21:04

0001 #ifndef G4HepEmElementData_HH
0002 #define G4HepEmElementData_HH
0003 
0004 /**
0005  * @file    G4HepEmElementData.hh
0006  * @struct  G4HepEmElementData
0007  * @author  M. Novak
0008  * @date    2020
0009  *
0010  * @brief All element related data used by ``G4HepEm``.
0011  *
0012  * All element related data, used by ``G4HepEm``, is stored in this simple data
0013  * structure. The G4HepEmElementData structure contains a collection of G4HepEmElemData
0014  * for each G4Element object that is used in the geometry. Such a G4HepEmElemData
0015  * stores a single element realted data required during the simulation.
0016  *
0017  * A single instance of this structure is created and stored in the `master`
0018  * G4HepEmRunManager when its InitializeGlobal() method is invoked by calling
0019  * the InitMaterialAndCoupleData() function declared in the G4HepEmMaterialInit
0020  * header file. This method extracts information form the already initialised
0021  * part of the Geant4 application (i.e. G4MaterialCutsCoupleTable) by reading all
0022  * G4MaterialCutsCouple objects used in the current geometry, translating their
0023  * G4Element objects into G4HepEmElemData strcutrues and stores in this single
0024  * G4HepEmElementData sturcture.
0025  *
0026  * In case of ``CUDA`` build, the data can be easily copied to the device by either
0027  * using the CopyElementDataToGPU() function or the more general CopyG4HepEmDataToGPU()
0028  * function: the first will copy only the specified G4HepEmElementData structure
0029  * while the second will (deep copy) all the members (including the G4HepEmElementData
0030  * one) of the G4HepEmData, top level data structure member of the (master)
0031  * G4HepEmRunManager.
0032  *
0033  */
0034 
0035 /** Data that describes a single element in ``G4HepEm``. */
0036 struct G4HepEmElemData {
0037 
0038   /** The atomic number (Z) of the element. */
0039   double  fZet = -1.0;
0040 
0041   /** \f$Z^{1/3}\f$ */
0042   double  fZet13 = 0.0;
0043 
0044   /** \f$Z^{2/3}\f$ */
0045   double  fZet23 = 0.0;
0046 
0047   /** Coulomb correction \f$ f_C \f$ */
0048   double  fCoulomb = 0.0;
0049 
0050   /** \f$ \ln(Z) \f$  */
0051   double  fLogZ = 0.0;
0052 
0053   /** \f$ F_{\text{el}}-f_c+F_{\text{inel}}/Z \f$  */
0054   double  fZFactor1 = 0.0;
0055 
0056   /** \f$ \exp \left[ \frac{42.038-F_{\text{low}}}{8.29} \right] -0.958 \f$ with \f$ Z_{\text{low}} = \frac{8}{3}\log(Z) \f$ */
0057   double  fDeltaMaxLow = 0.0;
0058 
0059   /** \f$ \exp \left[ \frac{42.038-F_{\text{high}}}{8.29} \right] -0.958 \f$ with \f$ F_{\text{high}} = 8[\log(Z)/3 + f_C] \f$ */
0060   double  fDeltaMaxHigh = 0.0;
0061 
0062   /** LPM variable \f$ 1/ln [ \sqrt{2}s1 ] \f$ */
0063   double  fILVarS1 = 0.0;
0064 
0065   /** LPM variable \f$ 1/ln[s1] \f$ */
0066   double  fILVarS1Cond = 0.0;
0067 
0068   /** Number of intervals in the Sandia table */
0069   int     fNumOfSandiaIntervals = 0;
0070   /** Starting energy of the intervals */
0071   double* fSandiaEnergies = nullptr; // [fNumOfSandiaIntervals]
0072   /** Coefficients for the interval (four per energy range) */
0073   double* fSandiaCoefficients = nullptr; // [4 x fNumOfSandiaIntervals]
0074 
0075   /** Binding energy of the k-shell */
0076   double  fKShellBindingEnergy = 0;
0077 };
0078 
0079 // Data for all elements that are used by G4HepEm.
0080 struct G4HepEmElementData {
0081   /** Maximum capacity of the below G4HepEmElemData structure container (max Z that can be stored).*/
0082   int     fMaxZet = 0;
0083   /** Collection of G4HepEmElemData structures indexed by the atomic number Z. */
0084   struct G4HepEmElemData* fElementData = nullptr;  // [fMaxZet]
0085 };
0086 
0087 /**
0088   * Allocates and pre-initialises an existing @ref G4HepEmMaterialData structure.
0089   *
0090   * This method is invoked from the InitMaterialAndCoupleData() function declared
0091   * in the G4HepEmMaterialInit header file. The input argument address of the
0092   * G4HepEmElementData structure pointer is the one stored in the G4HepEmData
0093   * member of the `master` G4HepEmRunManager and the initialisation should be
0094   * done by the master G4HepEmRunManager.
0095   *
0096   * @param [in][out] theElementData address of a G4HepEmElementData structure pointer. At termination,
0097   *   the correspondig pointer will be set to a memory location with a freshly allocated
0098   *   G4HepEmElementData structure. If the pointer was not null at input, the pointed
0099   *   memory is freed before the new allocation.
0100   */
0101 void AllocateElementData(struct G4HepEmElementData** theElementData);
0102 
0103 /**
0104  * Initializes a new @ref G4HepEmMaterialData structure
0105  *
0106  * This function default constructs an instance of G4HepEmMaterialData and returns
0107  * a pointer to the freshly constructed instance. It is the callees responsibility
0108  * to free the instance using @ref FreeElementData.
0109  *
0110  * @return Pointer to instance of @ref G4HepEmMaterialData
0111  */
0112 G4HepEmElementData* MakeElementData();
0113 
0114 /**
0115   * Frees a G4HepEmElementData structure.
0116   *
0117   * This function deallocates all dynamically allocated memory stored in the
0118   * input argument related G4HepEmElementData structure, deallocates the structure
0119   * itself and sets the input address to store a pointer to null. This makes the
0120   * corresponding input stucture cleared, freed and ready to be re-initialised.
0121   * The input argument is supposed to be the address of the corresponding pointer
0122   * member of the G4HepEmData member of the `master` G4HepEmRunManager.
0123   *
0124   * @param [in][out] theElementData memory address that stores pointer to a G4HepEmElementData
0125   *  structure. The memory is freed and the input address will store a null pointer
0126   *  at termination.
0127   */
0128 void FreeElementData (struct G4HepEmElementData** theElementData);
0129 
0130 
0131 #ifdef G4HepEm_CUDA_BUILD
0132 /**
0133   * Allocates memory for and copies the G4HepEmElementData structure from the
0134   * host to the device.
0135   *
0136   * The input arguments are supposed to be the corresponding members of the
0137   * G4HepEmData, top level data structure, stored in the `master` G4HepEmRunManager.
0138   *
0139   * @param onHost    pointer to the host side, already initialised G4HepEmElementData structure.
0140   * @param onDevice  host side address of a G4HepEmElementData structure memory pointer. The pointed
0141   *   memory is cleaned (if not null at input) and points to the device side memory at termination
0142   *   that stores the copied G4HepEmElementData structure.
0143   */
0144   void CopyElementDataToGPU(struct G4HepEmElementData* onHost, struct G4HepEmElementData** onDevice);
0145 
0146   /**
0147     * Frees all memory related to the device side G4HepEmElementData structure referred
0148     * by the pointer stored on the host side input argument address.
0149     *
0150     * @param onDevice host side address of a G4HepEmElementData structure located on the device side memory.
0151     *   The correspondig device memory will be freed and the input argument address will be set to null.
0152     */
0153   void FreeElementDataOnGPU(struct G4HepEmElementData** onDevice);
0154 #endif // DG4HepEm_CUDA_BUILD
0155 
0156 
0157 #endif // G4HepEmElementData_HH