0

I am trying to access the matrix elements of a G4RotationMatrix.

The G4RotationMatrix is typedef'd to HepRotation as follows typedef CLHEP::HepRotation G4RotationMatrix

One of the functions of HepRotation is defined as

double HepRotation::operator() (int i, int j) const {
  if (i == 0) {
    if (j == 0) { return xx(); }
    if (j == 1) { return xy(); }  
    if (j == 2) { return xz(); }
  } else if (i == 1) {
    if (j == 0) { return yx(); }
    if (j == 1) { return yy(); }
    if (j == 2) { return yz(); }
  } else if (i == 2) {
    if (j == 0) { return zx(); }
    if (j == 1) { return zy(); }
    if (j == 2) { return zz(); }
  }
  std::cerr << "HepRotation     subscripting: bad indices "
       << "(" << i << "," << j << ")" << std::endl;
  return 0.0;

Assuming it has been correctly defined to boost how and what do I code in Python to access the elements of the matrix which in my case is called rot ?

Keith Sloan
  • 125
  • 1
  • 12
  • I don’t get it : you are trying to interface python with c++ lib ? If so you should rewrite your question. And by the way, this kind of topic is already covered in several questions and tutorials. Refer to python package ctypes. – LoneWanderer Mar 16 '19 at 12:08
  • See https://stackoverflow.com/questions/145270/calling-c-c-from-python for instance – LoneWanderer Mar 16 '19 at 12:20
  • Sorry I don't get your answer either. I am trying to use the Geant4 C++ library from python. They have defined boost bindings for access from python. I am trying to access the matrix elements of a python variable that is created as a G4RotationMatrix i.e. rot=pv.GetObjectRotationValue() – Keith Sloan Mar 16 '19 at 13:32
  • That is my point : you did not tell us that in the first place. You should provide a minimal verifiable working example of what you are trying to do. – LoneWanderer Mar 16 '19 at 14:20
  • If I had a minimal verifiable working example I would not be asking the question. If I have a python variable rot that is a G4RotationMatrix which is a the same thing as a HepRotation and with Boost definitions to access you can call normal C++ method from python with rot.method(). So I want to access the individual elements of the matrix and I am guessing that the HepRotation::operator definition given will allow me to do this, but I don't know how/syntax etc – Keith Sloan Mar 16 '19 at 16:59
  • MMh found the header file of HepRotation and according to comments I should be able to access as rot[x][y] But when I try this with t = rot[1][1] I get an error message File "/usr/lib/freecad-daily/Mod/Geant4 /importGDML.py", line 113, in createFCmatrix t = rot[1][1] : 'G4RotationMatrix' object does not support indexing – Keith Sloan Mar 16 '19 at 17:36
  • Okay its seem I can index a HepMatrix and the only things I can find related to HepRotation are a bare class HepRotation; and HepMatrix & operator = ( const HepRotation &); – Keith Sloan Mar 16 '19 at 18:09
  • After a few minutes googling, I assume you are using this : http://geant4.web.cern.ch/ or this https://github.com/Geant4/geant4/tree/master/environments/g4py ? – LoneWanderer Mar 16 '19 at 19:58
  • Correct Using g4py – Keith Sloan Mar 16 '19 at 20:04

0 Answers0