Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:27

0001 
0002 #include "scuda.h"
0003 
0004 #include "G4Log.hh"
0005 #include "OPTICKS_LOG.hh"
0006 #include "SSys.hh"
0007 #include "spath.h"
0008 #include "NP.hh"
0009 
0010 
0011 struct U4LogTest
0012 {
0013     static std::string Prod( const char* v_, double v, const char* vsc_, double sc, const char* fvsc_ );
0014 
0015     static const char* FOLD ;
0016     unsigned ni ;
0017     static constexpr const unsigned NJ = 5 ;
0018 
0019     U4LogTest();
0020     std::string one(double u);
0021     void one_( DOUBLE4& dd, double d );
0022     void scan();
0023 
0024 };
0025 
0026 
0027 const char* U4LogTest::FOLD = spath::Resolve("$TMP/U4LogTest");
0028 
0029 
0030 U4LogTest::U4LogTest()
0031     :
0032     ni(SSys::getenvunsigned("U4LogTest_ni", 1000001))
0033 {
0034 }
0035 
0036 
0037 std::string U4LogTest::Prod( const char* v_, double v, const char* vsc_, double sc, const char* fvsc_  )
0038 {
0039     std::stringstream ss ;
0040     ss << " " << std::setw(10) << v_   << " " << std::setw(10) << std::fixed << std::setprecision(7) << v
0041        << " " << std::setw(10) << vsc_ << " " << std::setw(10) << std::fixed << std::setprecision(7) << v*sc
0042        << " " << std::setw(10) << fvsc_ << " " << std::setw(10) << std::fixed << std::setprecision(7) << float(v)*float(sc)
0043        ;
0044     std::string s = ss.str();
0045     return s ;
0046 }
0047 
0048 
0049 std::string U4LogTest::one( double u )
0050 {
0051     DOUBLE4 dd ;
0052     one_(dd, u );
0053 
0054     double sc = 1e7 ;
0055     std::stringstream ss ;
0056     ss
0057         << " u  " << std::setw(10) << std::fixed << std::setprecision(7) << u << std::endl
0058         << Prod("d0",dd.x,"d0*sc", sc, "f(d0)*f(sc)" ) << std::endl
0059         << Prod("f0",dd.y,"f0*sc", sc, "f(f0)*f(sc)" ) << std::endl
0060         << Prod("d4",dd.z,"d4*sc", sc, "f(d4)*f(sc)" ) << std::endl
0061         << Prod("f4",dd.w,"f4*sc", sc, "f(f4)*f(sc)" ) << std::endl
0062         ;
0063 
0064     std::string s = ss.str();
0065     return s ;
0066 }
0067 
0068 void U4LogTest::one_( DOUBLE4& dd, double d )
0069 {
0070     float  f = float(d) ;
0071     double d0 = -1.*std::log( d );
0072     float  f0 = -1.f*std::log( f );
0073     double d4 = -1.*G4Log( d ) ;
0074     float  f4 = -1.f*G4Logf( f ) ;
0075 
0076     dd.x = d0 ;
0077     dd.y = f0 ;
0078     dd.z = d4 ;
0079     dd.w = f4 ;
0080 }
0081 
0082 void U4LogTest::scan()
0083 {
0084     NP* a = NP::Make<double>(ni, NJ );
0085     double* aa = a->values<double>();
0086 
0087     for(unsigned i=0 ; i < ni ; i++)
0088     {
0089         double d =  double(i)/double(ni-1) ;
0090 
0091         DOUBLE4 dd ;
0092         one_(dd, d );
0093 
0094         aa[NJ*i+0] = d ;
0095         aa[NJ*i+1] = dd.x ;
0096         aa[NJ*i+2] = dd.y ;
0097         aa[NJ*i+3] = dd.z ;
0098         aa[NJ*i+4] = dd.w ;
0099     }
0100     a->save(FOLD, "scan.npy") ;
0101 }
0102 
0103 int main(int argc, char** argv)
0104 {
0105     U4LogTest t ;
0106     double u = SSys::getenvdouble("U", 0.) ;
0107     if( u > 0. ) std::cout << t.one(u) ;
0108     else t.scan();
0109 
0110     return 0 ;
0111 }