Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:59

0001 /**
0002  * Create an outline for a magnet and represent it as a ROOT PolyLine- allow for rotation
0003  */
0004 TPolyLine* TraceBox( float angle, float center_z, float center_x, float length, float aperture_radius, float outer_radius )
0005 {
0006   /* center of magnet box */
0007   TVector3* vcenter = new TVector3( center_z,
0008                     center_x,
0009                     0.0 );
0010 
0011   /* fill corner positions in 3D vector TVector objects for easier rotation */
0012   const unsigned npts = 5;
0013   TObjArray a;
0014 
0015   /* corner points in unrotated coordinate system */
0016   a.AddLast( new TVector3( 0.0 - ( length / 2. ),
0017                0.0 + outer_radius,
0018                0.0 ) );
0019 
0020   a.AddLast( new TVector3( 0.0 + ( length / 2. ),
0021                0.0 + outer_radius,
0022                0.0 ) );
0023 
0024   a.AddLast( new TVector3( 0.0 + ( length / 2. ),
0025                0.0 + aperture_radius,
0026                0.0 ) );
0027 
0028   a.AddLast( new TVector3( 0.0 - ( length / 2. ),
0029                0.0 + aperture_radius,
0030                0.0 ) );
0031 
0032   a.AddLast( new TVector3( 0.0 - ( length / 2. ),
0033                0.0 + outer_radius,
0034                0.0 ) );
0035 
0036   /* loop over array and rotate points coordinate system and move to real center */
0037   for ( int i = 0; i < npts; i++ )
0038     {
0039       /* calculated rotated x, y */
0040       float rotated_x = ( (TVector3*)a[i] )->X() * cos( angle ) - ( (TVector3*)a[i] )->Y() * sin( angle );
0041       float rotated_y = ( (TVector3*)a[i] )->X() * sin( angle ) + ( (TVector3*)a[i] )->Y() * cos( angle );
0042 
0043       /* add center offset */
0044       rotated_x += center_z;
0045       rotated_y += center_x;
0046 
0047       /* set vector coordinates to new x, y */
0048       ( (TVector3*)a[i] )->SetX( rotated_x );
0049       ( (TVector3*)a[i] )->SetY( rotated_y );
0050     }
0051 
0052   /* extract two 1-D arrays from array of vectors with corner points coordinates */
0053   float xarr[ npts ];
0054   float yarr[ npts ];
0055 
0056   for ( int i = 0; i < npts; i++ )
0057     {
0058       xarr[i] = ( (TVector3*)a[i] )->X();
0059       yarr[i] = ( (TVector3*)a[i] )->Y();
0060     }
0061 
0062   /* create and return TPolyLine object */
0063   return new TPolyLine(npts, xarr, yarr);
0064 }