// @(#)root/eve:$Id$ // Author: Matevz Tadel 2007 /************************************************************************* * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #include "TEveVector.h" #include "TVector3.h" //============================================================================== // TEveVector //============================================================================== //______________________________________________________________________________ // // Minimal, templated three-vector. // No TObject inheritance and virtual functions. // Also used in VSD. ClassImp(TEveVectorT); ClassImp(TEveVectorT); //______________________________________________________________________________ template void TEveVectorT::Dump() const { // Dump to stdout as "(x, y, z)\n". printf("(%f, %f, %f)\n", fX, fY, fZ); } //______________________________________________________________________________ template void TEveVectorT::Set(const TVector3& v) { // Set from TVector3. fX = v.x(); fY = v.y(); fZ = v.z(); } //______________________________________________________________________________ template TT TEveVectorT::Eta() const { // Calculate eta of the point, pretending it's a momentum vector. TT cosTheta = CosTheta(); if (cosTheta*cosTheta < 1) return -0.5* TMath::Log( (1.0-cosTheta)/(1.0+cosTheta) ); Warning("Eta","transverse momentum = 0, returning +/- 1e10"); return (fZ >= 0) ? 1e10 : -1e10; } //______________________________________________________________________________ template TT TEveVectorT::Normalize(TT length) { // Normalize the vector to length if current length is non-zero. // Returns the old magnitude. TT m = Mag(); if (m != 0) { length /= m; fX *= length; fY *= length; fZ *= length; } return m; } //______________________________________________________________________________ template TEveVectorT TEveVectorT::Orthogonal() const { // Returns an orthogonal vector (not normalized). Float_t xx = fX < 0 ? -fX : fX; Float_t yy = fY < 0 ? -fY : fY; Float_t zz = fZ < 0 ? -fZ : fZ; if (xx < yy) { return xx < zz ? TEveVectorT(0,fZ,-fY) : TEveVectorT(fY,-fX,0); } else { return yy < zz ? TEveVectorT(-fZ,0,fX) : TEveVectorT(fY,-fX,0); } } //______________________________________________________________________________ template void TEveVectorT::OrthoNormBase(TEveVectorT& a, TEveVectorT& b) const { // Set vectors a and b to be normal to this and among themselves, // both of length 1. a = Orthogonal(); TMath::Cross(this->Arr(), a.Arr(), b.Arr()); a.Normalize(); b.Normalize(); } template class TEveVectorT; template class TEveVectorT; //============================================================================== // TEveVector4 //============================================================================== //______________________________________________________________________________ // // Minimal, templated four-vector. // No TObject inheritance and virtual functions. // Also used in VSD. ClassImp(TEveVector4T); ClassImp(TEveVector4T); //______________________________________________________________________________ template void TEveVector4T::Dump() const { // Dump to stdout as "(x, y, z; t)\n". printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT); } template class TEveVector4T; template class TEveVector4T; //============================================================================== // TEveVector2T //============================================================================== //______________________________________________________________________________ // // Minimal, templated two-vector. // No TObject inheritance and virtual functions. // Also used in VSD. ClassImp(TEveVector2T); ClassImp(TEveVector2T); //______________________________________________________________________________ template void TEveVector2T::Normalize(TT length) { // Normalize the vector to length if current length is non-zero. Float_t m = Mag(); if (m != 0) { m = length / m; fX *= m; fY *= m; } } //______________________________________________________________________________ template void TEveVector2T::Dump() const { // Dump to stdout as "(x, y)\n". printf("(%f, %f)\n", fX, fY); } template class TEveVector2T; template class TEveVector2T;