Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:39

0001 #include <cassert>
0002 #include <cmath>
0003 #include <sstream>
0004 #include <iomanip>
0005 
0006 #include "SMath.hh"
0007 
0008 /**
0009 SMath::cos_pi
0010 ------------------
0011 
0012       
0013               Y
0014               |
0015               |
0016               |
0017     -X -------O--------- phi_pi = 0.   X
0018               |
0019               |
0020               |
0021              -Y
0022 
0023 TODO: some platforms have sinpi cospi functions, could use those when available
0024 
0025 **/
0026 
0027 double SMath::cos_pi( double phi_pi )
0028 {
0029     double cosPhi_0 = std::cos(phi_pi*M_PI) ; 
0030     double cosPhi_1 = cosPhi_0 ; 
0031 
0032     if( phi_pi == 0.0  ) cosPhi_1 = 1. ; 
0033     if( phi_pi == 0.5  ) cosPhi_1 = 0. ; 
0034     if( phi_pi == 1.0  ) cosPhi_1 = -1. ; 
0035     if( phi_pi == 1.5  ) cosPhi_1 = 0. ; 
0036     if( phi_pi == 2.0  ) cosPhi_1 = 1. ; 
0037 
0038     assert( std::abs(cosPhi_0 - cosPhi_1) < 1e-6 ) ; 
0039     return cosPhi_1 ; 
0040 } 
0041 
0042 double SMath::sin_pi( double phi_pi )
0043 {
0044     double sinPhi_0 = std::sin(phi_pi*M_PI) ; 
0045     double sinPhi_1 = sinPhi_0 ; 
0046 
0047     if( phi_pi == 0.0  ) sinPhi_1 = 0. ; 
0048     if( phi_pi == 0.5  ) sinPhi_1 = 1. ; 
0049     if( phi_pi == 1.0  ) sinPhi_1 = 0. ; 
0050     if( phi_pi == 1.5  ) sinPhi_1 = -1. ; 
0051     if( phi_pi == 2.0  ) sinPhi_1 = 0. ; 
0052 
0053     assert( std::abs(sinPhi_0 - sinPhi_1) < 1e-6 ) ; 
0054     return sinPhi_1 ; 
0055 } 
0056 
0057 
0058 std::string SMath::Format( std::vector<std::pair<std::string, double>>& pairs, int l, int w, int p)
0059 {
0060     std::stringstream ss ; 
0061     for(unsigned i=0 ; i < pairs.size() ; i++)
0062     {
0063         const std::pair<std::string, double>& pair = pairs[i] ; 
0064         ss
0065             << std::setw(3) << i << " " 
0066             << std::setw(l) << pair.first
0067             << std::scientific << std::setw(w) << std::setprecision(p) << pair.second  
0068             << std::endl
0069             ;
0070     }
0071     std::string s = ss.str(); 
0072     return s ; 
0073 }
0074 
0075 
0076