Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:57

0001 
0002 #ifndef PHFIELD_PHFIELD2D_H
0003 #define PHFIELD_PHFIELD2D_H
0004 
0005 #include "PHField.h"
0006 
0007 #include <map>
0008 #include <string>
0009 #include <tuple>
0010 #include <vector>
0011 
0012 class PHField2D : public PHField
0013 {
0014   typedef std::tuple<float, float> trio;
0015 
0016  public:
0017   PHField2D(const std::string &filename, const int verb = 0, const float magfield_rescale = 1.0);
0018 
0019   //! access field value
0020   //! Follow the convention of G4ElectroMagneticField
0021   //! @param[in]  Point   space time coordinate. x, y, z, t in Geant4/CLHEP units
0022   //! @param[out] Bfield  field value. In the case of magnetic field, the order is Bx, By, Bz in in Geant4/CLHEP units
0023   void GetFieldValue(const double Point[4], double *Bfield) const override;
0024 
0025   //! access field value
0026   void GetFieldValue_nocache(const double Point[4], double *Bfield) const override;
0027 
0028   void GetFieldCyl(const double CylPoint[4], double *Bfield) const;
0029 
0030   void GetFieldCyl_nocache(const double CylPoint[4], double *Bfield) const;
0031 
0032   protected:
0033   // < i, j, k > , this allows i and i+1 to be neighbors ( <i,j,k>=<z,r,phi> )
0034   std::vector<std::vector<float> > BFieldZ_;
0035   std::vector<std::vector<float> > BFieldR_;
0036   std::vector<std::vector<float> > BFieldPHI_;
0037 
0038   // maps indices to values z_map[i] = z_value that corresponds to ith index
0039   std::vector<float> z_map_;    // < i >
0040   std::vector<float> r_map_;    // < j >
0041   std::vector<float> phi_map_;  // < k >
0042 
0043   float maxz_, minz_;  // boundaries of magnetic field map cyl
0044   double magfield_unit;
0045 
0046  private:
0047   void print_map(std::map<trio, trio>::iterator &it) const;
0048   // mutable allows to change internal data even in const methods
0049   // I don't like this too much but these are cached values to speed up
0050   // the field lookup by a lot
0051   // I want them to be data members so we can run 2 fieldmaps in parallel
0052   // and still have caching. Putting those as static variables into
0053   // the implementation will prevent this
0054 
0055   mutable unsigned int r_index0_cache;
0056   mutable unsigned int r_index1_cache;
0057   mutable unsigned int z_index0_cache;
0058   mutable unsigned int z_index1_cache;
0059 };
0060 
0061 #endif