Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
0002 #include <vector>
0003 #include "G4PVPlacement.hh"
0004 
0005 #include "U4RotationMatrix.h"
0006 #include "U4Material.hh"
0007 #include "U4VolumeMaker.hh"
0008 #include "U4Transform.h"
0009 #include "NP.hh"
0010 #include "strid.h"
0011 
0012 #include <glm/gtx/string_cast.hpp>
0013 
0014 
0015 G4VPhysicalVolume* MakePV()
0016 {
0017     G4LogicalVolume* lv = U4VolumeMaker::Box_(1000., U4Material::VACUUM, "pfx" ); 
0018 
0019     G4ThreeVector tla(10., 20., 30.) ; 
0020 
0021     double phi = glm::pi<double>()/4. ; 
0022     U4RotationMatrix* rot = U4RotationMatrix::ZZ(phi); 
0023 
0024     const char* pv_name = "pv" ;
0025     G4LogicalVolume* mother_lv = nullptr ; 
0026 
0027     G4VPhysicalVolume* pv = new G4PVPlacement(rot, tla, lv, pv_name, mother_lv, false, 0);
0028 
0029     return pv ; 
0030 }
0031 
0032 void test_Write()
0033 {
0034     const G4VPhysicalVolume* pv = MakePV(); 
0035 
0036     {
0037         glm::tmat4x4<double> tr0(1.); 
0038         glm::tmat4x4<double> tr1(1.); 
0039         U4Transform::WriteObjectTransform( glm::value_ptr(tr0), pv) ;
0040         U4Transform::WriteFrameTransform(  glm::value_ptr(tr1), pv) ;
0041         std::cout << glm::to_string(tr0) << std::endl ; 
0042         std::cout << glm::to_string(tr1) << std::endl ; 
0043     }
0044 
0045     {
0046         NP* a = NP::Make<double>(2,4,4); 
0047         U4Transform::WriteObjectTransform( a->values<double>() + 0  , pv) ;
0048         U4Transform::WriteFrameTransform(  a->values<double>() + 16 , pv) ;
0049         
0050         std::vector<glm::tmat4x4<double>> m(2) ; 
0051         memcpy((double*)m.data(), a->cvalues<double>() ,  a->arr_bytes() ); 
0052 
0053         std::cout << glm::to_string(m[0]) << std::endl ; 
0054         std::cout << glm::to_string(m[1]) << std::endl ; 
0055     }
0056 }
0057 
0058 
0059 void test_Get()
0060 {
0061     const G4VPhysicalVolume* pv = MakePV(); 
0062 
0063     glm::tmat4x4<double> m2w(1.) ;  
0064     U4Transform::GetObjectTransform(m2w, pv); 
0065 
0066     glm::tmat4x4<double> w2m(1.) ;  
0067     U4Transform::GetFrameTransform(w2m, pv); 
0068 
0069     glm::tmat4x4<double> m2w_w2m = m2w * w2m ;  
0070 
0071     std::cout << strid::Desc_("m2w", "w2m", "m2w_w2m", m2w, w2m, m2w_w2m ) << std::endl ; 
0072 }
0073 
0074 void test_GetScaleTransform()
0075 {
0076     std::cout << "test_GetScaleTransform " << std::endl ; 
0077 
0078     glm::tmat4x4<double> scale(1.) ;  
0079 
0080     U4Transform::GetScaleTransform(scale, 1.5, 1.5, 1.0 ); 
0081 
0082     std::cout << " scale " << glm::to_string(scale ) << std::endl ; 
0083 }
0084 
0085 
0086 
0087 int main(int argc, char** argv)
0088 {
0089     //test_Get(); 
0090     //test_Write(); 
0091     test_GetScaleTransform(); 
0092 
0093     return 0 ; 
0094 }