Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraceBox.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TraceBox.h
1 
4 TPolyLine* TraceBox( float angle, float center_z, float center_x, float length, float aperture_radius, float outer_radius )
5 {
6  /* center of magnet box */
7  TVector3* vcenter = new TVector3( center_z,
8  center_x,
9  0.0 );
10 
11  /* fill corner positions in 3D vector TVector objects for easier rotation */
12  const unsigned npts = 5;
13  TObjArray a;
14 
15  /* corner points in unrotated coordinate system */
16  a.AddLast( new TVector3( 0.0 - ( length / 2. ),
17  0.0 + outer_radius,
18  0.0 ) );
19 
20  a.AddLast( new TVector3( 0.0 + ( length / 2. ),
21  0.0 + outer_radius,
22  0.0 ) );
23 
24  a.AddLast( new TVector3( 0.0 + ( length / 2. ),
25  0.0 + aperture_radius,
26  0.0 ) );
27 
28  a.AddLast( new TVector3( 0.0 - ( length / 2. ),
29  0.0 + aperture_radius,
30  0.0 ) );
31 
32  a.AddLast( new TVector3( 0.0 - ( length / 2. ),
33  0.0 + outer_radius,
34  0.0 ) );
35 
36  /* loop over array and rotate points coordinate system and move to real center */
37  for ( int i = 0; i < npts; i++ )
38  {
39  /* calculated rotated x, y */
40  float rotated_x = ( (TVector3*)a[i] )->X() * cos( angle ) - ( (TVector3*)a[i] )->Y() * sin( angle );
41  float rotated_y = ( (TVector3*)a[i] )->X() * sin( angle ) + ( (TVector3*)a[i] )->Y() * cos( angle );
42 
43  /* add center offset */
44  rotated_x += center_z;
45  rotated_y += center_x;
46 
47  /* set vector coordinates to new x, y */
48  ( (TVector3*)a[i] )->SetX( rotated_x );
49  ( (TVector3*)a[i] )->SetY( rotated_y );
50  }
51 
52  /* extract two 1-D arrays from array of vectors with corner points coordinates */
53  float xarr[ npts ];
54  float yarr[ npts ];
55 
56  for ( int i = 0; i < npts; i++ )
57  {
58  xarr[i] = ( (TVector3*)a[i] )->X();
59  yarr[i] = ( (TVector3*)a[i] )->Y();
60  }
61 
62  /* create and return TPolyLine object */
63  return new TPolyLine(npts, xarr, yarr);
64 }