Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef G4HepEmMatCutData_HH
0002 #define G4HepEmMatCutData_HH
0003 
0004 /**
0005  * @file    G4HepEmMatCutData.hh
0006  * @struct  G4HepEmMatCutData
0007  * @author  M. Novak
0008  * @date    2020
0009  *
0010  * @brief All material - cuts couple related data used by ``G4HepEm``.
0011  *
0012  * All material - cuts (secondary production threshold) couple related data,
0013  * used by ``G4HepEm``, is stored in this simple data structure. The
0014  * G4HepEmMatCutData structure contains a collection of G4HepEmMCCData for each
0015  * G4MaterialCutsCouple object that is used in the geometry. Such a G4HepEmMCCData
0016  * stores a single material-cuts couple realted data required during the simulation.
0017  *
0018  * A single instance of this structure is created and stored in the `master`
0019  * G4HepEmRunManager when its InitializeGlobal() method is invoked by calling
0020  * the InitMaterialAndCoupleData() function declared in the G4HepEmMaterialInit
0021  * header file. This method extracts information form the already initialised
0022  * part of the Geant4 application (i.e. G4MaterialCutsCoupleTable) by reading all
0023  * G4MaterialCutsCouple objects used in the current geometry, translating them
0024  * into G4HepEmMCCData strcutrues and store in this single G4HepEmMatCutData sturcture.
0025  *
0026  * In case of ``CUDA`` build, the data can be easily copied to the device by either
0027  * using the CopyMatCutDataToGPU() function or the more general CopyG4HepEmDataToGPU()
0028  * function: the first will copy only the specified G4HepEmMatCutData structure
0029  * while the second will (deep copy) all the members (including the G4HepEmMatCutData
0030  * one) of the G4HepEmData, top level data structure member of the (master)
0031  * G4HepEmRunManager.
0032  *
0033  * @note  only the data members that are needed on the device side are copied to
0034  * the device memory. This means, that only the G4HepEmMatCutData::fMatCutData
0035  * collection of the G4HepEmMCCData structures is copied to the device memory
0036  * together with the G4HepEmMatCutData::fNumMatCutData length of this collection.
0037  *
0038  */
0039 
0040 /** Data that describes a single matrial-cuts couple in ``G4HepEm``. */
0041 struct G4HepEmMCCData {
0042   /** Secondary \f$e^-\f$ production threshold energy [MeV]. */
0043   double  fSecElProdCutE = 0.0;
0044   /** Secondary \f$e^+\f$ production threshold energy [MeV]. */
0045   double  fSecPosProdCutE = 0.0;
0046   /** Secondary \f$\gamma\f$ production threshold energy [MeV]. */
0047   double  fSecGamProdCutE = 0.0;
0048   /** Logarithm of the above secondary \f$\gamma\f$ production threshold. */
0049   double  fLogSecGamCutE = 0.0;
0050   /** Index of its material realted data: index of its G4HepEmMatData in the G4HepEmMaterialData. */
0051   int     fHepEmMatIndex = -1;
0052   /** Index of the corresponding G4MaterialCutsCouple object.*/
0053   int     fG4MatCutIndex = -1;
0054   /** Index of the Geant4 detector region to which this material-cut belongs to. */
0055   int     fG4RegionIndex = -1;
0056 };
0057 
0058 // Data for all matrial cuts couple that are used by G4HepEm.
0059 struct G4HepEmMatCutData {
0060   /** Number of G4MaterialCutsCouple objects in ``Geant4`` (irrespectively if used or not).  */
0061   int      fNumG4MatCuts = 0;
0062   /** Number of G4HepEmMCCData structure in ``G4HepEm`` (only the used G4MaterialCutsCouple objects are translated). */
0063   int      fNumMatCutData = 0;
0064   /** Array that translates a Geant4 G4MaterialCutsCouple object index to the correspondig G4HepEmMCCData index in the collection below.*/
0065   int*     fG4MCIndexToHepEmMCIndex = nullptr;  // [fNumG4MatCuts]
0066   /** Collection of G4HepEmMCCData structures for all material-cuts couples used in the current geometry.*/
0067   struct G4HepEmMCCData* fMatCutData = nullptr; // [fNumMatCutData]
0068 };
0069 
0070 /**
0071   * Allocates and pre-initialises the G4HepEmMatCutData structure.
0072   *
0073   * This method is invoked from the InitMaterialAndCoupleData() function declared
0074   * in the G4HepEmMaterialInit header file. The input argument address of the
0075   * G4HepEmMatCutData structure pointer is the one stored in the G4HepEmData
0076   * member of the `master` G4HepEmRunManager and the initialisation should be
0077   * done by the master G4HepEmRunManager.
0078   *
0079   * @param theMatCutData address of a G4HepEmMatCutData structure pointer. At termination,
0080   *   the correspondig pointer will be set to a memory location with a freshly allocated
0081   *   G4HepEmMatCutData structure. If the pointer is not null at input, the pointed
0082   *   memory is freed before the new allocation.
0083   * @param[in] numG4MatCuts number of Geant4 material-cuts couple objects (irrespectively if used or not).
0084   *   It determines the maximum value of the G4MaterialCutsCouple object index.
0085   * @param[in] numUsedG4MatCuts number of Geant4 material-cuts couple objects used in the current geometry.
0086   *   It determines the number of the G4HepEmMCCData structures.
0087   */
0088 void AllocateMatCutData(struct G4HepEmMatCutData** theMatCutData, int numG4MatCuts, int numUsedG4MatCuts);
0089 
0090 
0091 /**
0092  * Initializes a new @ref G4HepEmMatCutData structure
0093  *
0094  * This function constructs and returns an instance of G4HepEmMatCutData to hold a given number of indices
0095  * to Geant4 material-cuts couple objects and their corresponding G4HepEmMCCData instance.
0096  * It is the callees responsibility to free the instance using @ref FreeMatCutData.
0097  *
0098   * @param[in] numG4MatCuts number of Geant4 material-cuts couple objects
0099   * @param[in] numUsedG4MatCuts number of Geant4 material-cuts couple objects used in the current geometry.
0100   * @return Pointer to instance of @ref G4HepEmMatCutData
0101  */
0102 G4HepEmMatCutData* MakeMatCutData(int numG4MatCuts, int numUsedG4MatCuts);
0103 
0104 /**
0105   * Frees a G4HepEmMatCutData structure.
0106   *
0107   * This function deallocates all dynamically allocated memory stored in the
0108   * input argument related G4HepEmMatCutData structure, deallocates the structure
0109   * itself and sets the input address to store a pointer to null. This makes the
0110   * corresponding input stucture cleared, freed and ready to be re-initialised.
0111   * The input argument is supposed to be the address of the corresponding pointer
0112   * member of the G4HepEmData member of the `master` G4HepEmRunManager.
0113   *
0114   * @param theMatCutData memory address that stores pointer to a G4HepEmMatCutData
0115   *  structure. The memory is freed and the input address will store a null pointer
0116   *  at termination.
0117   */
0118 void FreeMatCutData (struct G4HepEmMatCutData** theMatCutData);
0119 
0120 
0121 #ifdef G4HepEm_CUDA_BUILD
0122   /**
0123     * Allocates memory for and copies the G4HepEmMatCutData structure from the host
0124     * to the device.
0125     *
0126     * Only the G4HepEmMatCutData::fMatCutData collection of the G4HepEmMCCData
0127     * structures is copied to the device together with the G4HepEmMatCutData::fNumMatCutData
0128     * length of this collection.
0129     *
0130     * The input arguments are supposed to be the corresponding members of the
0131     * G4HepEmData, top level data structure, stored in the `master` G4HepEmRunManager.
0132     *
0133     * @param onHost    pointer to the host side, already initialised G4HepEmMatCutData structure.
0134     * @param onDevice  host side address of a G4HepEmMatCutData structure memory pointer. The pointed
0135     *   memory is cleaned (if not null at input) and points to the device side memory at termination
0136     *   that stores the copied G4HepEmMatCutData structure.
0137     */
0138   void CopyMatCutDataToGPU(struct G4HepEmMatCutData* onHost, struct G4HepEmMatCutData** onDevice);
0139 
0140   /**
0141     * Frees all memory related to the device side G4HepEmMatCutData structure referred
0142     * by the pointer stored on the host side input argument address.
0143     *
0144     * @param onDevice host side address of a G4HepEmMatCutData structure located on the device side memory.
0145     *   The correspondig device memory will be freed and the input argument address will be set to null.
0146     */
0147   void FreeMatCutDataOnGPU(struct G4HepEmMatCutData** onDevice);
0148 #endif // DG4HepEm_CUDA_BUILD
0149 
0150 #endif // G4HepEmMatCutData_HH