// sv-1.cc // A ZOOM PhysicsVectors tutorial example // // Tutorial example 1 for the SpaceVector class: // // Construction and component access // // * Constructing SpaceVectors and UnitVectors // * Output to ostreams // * Constructing an array of SpaceVectors // * Using different forms of coordinates // * Changing individual components // * Using pseudorapidity instead of theta // Key lines are marked by // <------------- // Get the SpaceVector class #include "ZMutility/ZMenvironment.h" #include "ZMutility/FixedTypes.h" #include "PhysicsVectors/SpaceVector.h" ZM_USING_NAMESPACE( zmpv ) USING( std::cout) USING( std::endl) // These classes themselves pull in FixedTypes, but just to // remind ourselves that we are using Float8, not double, for // 64-bit floats... #include "ZMutility/FixedTypes.h" ZM_USING_NAMESPACE( zmfxt ) // This example will use iostream output, so get that -- // in a portable way. #include "ZMutility/iostream" using std::cout; using std::endl; const Float8 PI = 3.1415926535897931; int main() { // ***** Constructing a SpaceVectors and UnitVectors // ***** Output to ostreams // Here is how to construct a vector from x, y, z: //------------------------------------------------ cout << "Constructing v1 from Cartesian coordinates \n"; Float8 x = 3; Float8 y = -4; Float8 z = 12; SpaceVector v1 ( x, y, z ); // <------------- // Here is how to output a SpaceVector: //------------------------------------- cout << "v1 =" << v1 << endl; // <------------- // Here is how to construct a vector from r, theta, phi. //------------------------------------------------------ cout << "Constructing v2 from Spherical polar coordinates \n"; Float8 r = 39; Float8 theta = PI/4; // PI is defined in the package Float8 phi = PI/6; SpaceVector v2 ( r, theta, RADIANS, phi, RADIANS ); // <------------- // The keyword RADIANS allows the class to recognize the // form of coordinates, and tells that the angles are in // radians. cout << "v2 =" << v2 << endl; // Here is how to construct a vector from rho, phi, z: //---------------------------------------------------- cout << "Constucting v2 from Cylindrical coordinates \n"; Float8 rho = 5; SpaceVector v3 ( rho, phi, RADIANS, z ); // <------------- cout << "v3 =" << v3 << endl; // ***** Constructing an array of SpaceVectors // Here is how to construct an array of SpaceVectors: //--------------------------------------------- // These hundred vectors will be initialized to (0,0,0) SpaceVector vv [100]; // This tutorial does not make use of these. // ***** Using different forms of coordinates // Here is how to obtain the polar coordinates of a SpaceVector: //-------------------------------------------------------------- // Remember, v1 was constructed from x, y, z. r = v1.r(); // <------------- theta = v1.theta(); // <------------- phi = v1.phi(); // <------------- cout << "v1 has r= " << r << " theta = " << theta << " phi = " << phi << endl; // You can output a component, say the cylindrical rho, directly: cout << "v1.rho is " << v1.rho() << endl; // <------------- // Here is how to obtain the Cartesian coordinates of a SpaceVector: //------------------------------------------------------------------ // Remember, v2 was constructed from r, theta, and phi x = v2.x(); // <------------- y = v2.y(); // <------------- z = v2.z(); // <------------- cout << "v2 has x= " << x << " y = " << y << " z = " << z << endl; // ***** Changing individual components // Here is how to change the y Cartesian component, // keeping x and z fixed: //--------------------------------------------------- cout << "v1 =" << v1 << endl; v1.setY( 4 ); // <------------- cout << "Now v1 =" << v1 << endl; // You can also use the modify/assign operators v1.setZ( v1.z() * -1 ); // <------------- // Here is how to change the r Spherical polar component, // keeping theta and phi fixed: //--------------------------------------------------- v1.setR( 26 ); // <------------- // It used to be 13, so this doubled v1. cout << "Now v1 =" << v1 << endl; //--> Now v1 = ( 6, 8, -24 ) // Here is how to change all three components at once: //----------------------------------------------------- // Remember, v2 was constructed from r, theta, phi. // But we now change it, expressing coordinates as rho, phi, z. v2.set ( 5, .2, RADIANS, 25 ); // <------------- cout << "Now v2 =" << v2 << endl; // ***** Using pseudorapidity instead of theta // Here is how to obtain eta of a vector //-------------------------------------- Float8 pseudoRap = v2.eta(); // <------------- cout << "The pseudo-rapidity eta of " << v2 << " is " << pseudoRap << endl; // Here is how to construct a vector with known pseudorapidity: //------------------------------------------------------------- r = 20; Float8 eta = 3.5; // The theta component in spherical coordinates can be expressed // by supplying eta instead. The phi component cannot. cout << "Constructing v4 from r, eta, phi \n"; SpaceVector v4 ( r, eta, ETA, phi, RADIANS ); // <------------- cout << "v4 =" << v4 << endl; // Here is how to use eta just like the coordinate theta: //------------------------------------------------------- // You can read off eta: eta = v1.eta(); // <------------- cout << "The pseudorapidity of" << v1 << "is " << v1.eta() << endl; // You can change eta, keeping r and phi fixed: cout << "v1 =" << v1 << endl; cout << "v1 has r= " << v1.r() << " eta = " << v1.eta() << " phi = " << v1.phi() << endl; v1.setEta( 4.2 ); // <------------- cout << "v1 =" << v1 << endl; cout << "Now v1 has r= " << v1.r() << " eta = " << v1.eta() << " phi = " << v1.phi() << endl; return 0; } /* end of main */