## Feature #924

### Beam Rotation

0%

**Description**

I'm not sure if this is already a feature or not but can we have add a rotation to the beam? I.e. we give the position of the beam in the worlds volume and also add a rotation to this as well so the beam can be placed with more flexibility?

#### Updated by Rogers, Chris over 10 years ago

**Category**set to*Simulation***Target version**set to*Future MAUS release*

So the basic concept:

In src/map/MapPyBeamMaker we allow several options like "reference", "transverse", etc. So need to add another item to this list called "rotation" that takes a three vector "x", "y", "z". The "rotation" command should apply a rotation to input particle data that

- rotates through z by angle beam_def["rotation"]["z"]
- rotates through z by angle beam_def["rotation"]["y"]
- rotates through z by angle beam_def["rotation"]["x"]

- rotation is non-commutative so you have to get the order right.
- beam_def["reference"] object is actually a MAUS primary particle, so don't edit this unless you want to faff with the whole data structure.
- there is some code and tests in my branch. I got as far as reading in the new beam command and started to think about doing the rotation.

- obviously unit test that the rotation is done correctly
- also please add an integration test that checks that the rotation is the same as a Geant4 physical rotation. So for example, if you have a geometry like
________________ | | | BOX B | |________________| WORLD o -> ________________ | | | BOX A | |________________|

where **o** is a particle moving in the direction of the arrow; then apply a rotation to the boxes; then apply the same rotation to the particle; the particle should not intersect the boxes. Maybe you can make something more elegant.

#### Updated by Rogers, Chris over 10 years ago

**Assignee**changed from*Rogers, Chris*to*Littlefield, Matthew*

#### Updated by Littlefield, Matthew over 10 years ago

I think I have got it so its pulling the rotation from the configuration defaults. You said that I need to apply this rotation to the input particle data. Could you elaborate a little of this please? I'm not sure how to alter the input particle data?

#### Updated by Littlefield, Matthew over 10 years ago

Scratch that last comment I was missing didn't see all the code you posted. Would you mind explaining what is going on in this part of your code please?

if self.rotation == None: return hit cx = math.cos(self.rotation["x"]) sx = math.sin(self.rotation["x"]) cy = math.cos(self.rotation["y"]) sy = math.sin(self.rotation["y"]) cz = math.cos(self.rotation["z"]) sz = math.sin(self.rotation["z"]) rot_matrix = numpy.matrix([[1., 0., 0.], [0., cx, -sx], [0., sx, cx],])*\ numpy.matrix([[cy, 0., sy], [0., 1., 0.], [-sy, 0., cy],])*\ numpy.matrix([[cz, -sz, 0.], [sz, cz, 0.], [0., 0., 0.],])

I can see that the object hit is

Hit.new_from_dict({'local_weight': 1.0, 'energy': 228.37452951150374, 'pid': -13, 'ey': 0.0, 'ex': 0.0, 'ez': 0.0, 'e_dep': 0.0, 'pz': 197.62770972027104, 'event_number': 0, 'px': 37.46616549724004, 'py': -23.039315276523702, 'charge': 0.0, 'station': 0, 'global_weight': 1.0, 'status': 0, 'proper_time': 0.0, 'path_length': 0.0, 'particleNumber': 0, 'particle_number': 0, 'bx': 0.0, 'by': 0.0, 'bz': 0.0, 'sz': 0.0, 'sy': 0.0, 'sx': 0.0, 'eventNumber': 0, 'mass': 105.6583668, 't': 201756.07158053783, 'y': 52.97936343217816, 'x': 39.98097631577003, 'z': 0.0})

and I take it that this is what we need to add the rotation to?

Cheers :-)

#### Updated by Rogers, Chris over 10 years ago

I was trying to prepare a transformation matrix to apply using `xboa.Hit.Hit.abelian_transformation(...)`

function. So probably one would perform a transformation in (x,y,z) and the same transformation in (px, py, pz).

#### Updated by Littlefield, Matthew over 10 years ago

Just to make sure. That transform would be applied to x,px,y,py,z,pz in the hit object I just posted?

#### Updated by Rogers, Chris over 10 years ago

On the python command line...

import xboa.Hit help(xboa.Hit.Hit.abelian_transformation)

Returns

Help on method abelian_transformation in module xboa.Hit: abelian_transformation(self, rotation_list, rotation_matrix, translation_dict={}, origin_dict={}, mass_shell_variable='') unbound xboa.Hit.Hit method Perform an abelian transformation about the origin, i.e. V_out - O = R*(V_in-O) + T. Then force E^2 = p^2 + m^2 rotation_list = list of variables to be rotated rotation_matrix = matrix R translation_dict = dict of strings from set_variables() to floats. Becomes O mass_shell_variable = string from list mass_shell_variables() origin_dict = dict of strings from set_variables() to floats. Becomes t e.g. hit.abelian_transformation(['x','px'], array[[1,0.5],[0,1]],{'x':10},'energy') will look like a drift space plus a translation

This would be two separate calls, one on `['x', 'y', 'z']`

and the other on `['px', 'py', 'pz']`

, something like

hit.abelian_transformation(['x', 'y', 'z'], rot_matrix) hit.abelian_transformation(['px', 'py', 'pz'], rot_matrix)

#### Updated by Rogers, Chris over 10 years ago

**Status**changed from*Open*to*Rejected*

Was this ever implemented?