BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//////////////////////////////////////////////////////////////////////////////////
//
//
//  BrPlane3D defines a general 3-plane class. BrPlane3D is part of the geometry 
//  classes. This is a general class only coupled to ROOT by having the objects 
//  being derived from TObject. The main reasons for doing this is to be able to 
//  use the ROOTs interactive features. It is intended to be used
//  by detector geometry , tracking, and display classes by using common
//  geometry concepts. It is also intended to work together with other geometry clasess
//  like BrLine3D, BrVector3D and likely other 
//  The coupling to ROOT is loose. The classes are derived from TObject, mainly
//  to be able to use browsers and other general ROOT utilities. Drawing has not
//  been implemented here again to maintain a very loose coupling.
//
//  Such general classes has of course been implemented by numerous people, and
//  design choices made. As such example the CLHEP should be acknowledged.
//
//  The plane is specified as fA*x + fB*y + fC*z + fD = 0.  The object can be 
//  created by either directly specifying the plane coefficients, fA, fB, fC and fD
//  or by specifying three points on the plane either by using BrVector3D,
//  by specifying the x,y,z coordinates of the three points explicitely,
//  or by specifiing a point (ie, vector) and a vector normal to the plane.
//  The constructor with a,b,c may fail since (fa,fb, fc) must be different from
// the zero vector.
//
//
/////////////////////////////////////////////////////////////////////////////////

//  $Id: BrPlane3D.cxx,v 1.2 2001/07/19 18:11:14 ekman Exp $
//  $Author: ekman $
//  $Date: 2001/07/19 18:11:14 $
//
//
#include "BrPlane3D.h"
#include "BrVector3D.h"
#include "BrLine3D.h"
#include <cmath>

#include "TMath.h"

ClassImp(BrPlane3D);

//____________________________________________________________________
 BrPlane3D::BrPlane3D(const BrVector3D &p1, const BrVector3D &p2, 
		     const BrVector3D &p3)
{
  //Constructor
  //Derive a plane from 3 points specified as point objects.

  Set(p1, p2, p3);
}

//____________________________________________________________________
 BrPlane3D::BrPlane3D(const Double_t x1, const Double_t y1, const Double_t z1,
                     const Double_t x2, const Double_t y2, const Double_t z2,
                     const Double_t x3, const Double_t y3, const Double_t z3 )
{
  //Constructor
  //Derive a plane from 3 points specified explicitly.
  
  fA = y1 * (z2 - z3) + y2 * (z3 - z1) + y3 * (z1 - z2);
  fB = z1 * (x2 - x3) + z2 * (x3 - x1) + z3 * (x1 - x2);
  fC = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
  fD = -( x1 * (y2 * z3 - y3 * z2) + x2 * (y3 * z1 - y1 * z3) + x3 * (y1 * z2 - y2 * z1));
}


//____________________________________________________________________
 BrPlane3D::BrPlane3D(const BrVector3D &point, const BrVector3D &normal)
{
  //Constructor
  //Derive a plane from a point and a vector normal to the plane.
  //
  fA = normal[0];
  fB = normal[1];
  fC = normal[2];
  fD = - (fA*point[0]+fB*point[1]+fC*point[2]);
}

//____________________________________________________________________
const Double_t& BrPlane3D::operator [] (size_t i) const {
  if (i==0)
    return fA;
  else if (i == 1)
    return fB;
  else if (i == 2)
    return fC;
  else
    return fD;
}

//____________________________________________________________________
Double_t& BrPlane3D::operator [] (size_t i) {
  if (i==0)
    return fA;
  else if (i == 1)
    return fB;
  else if (i == 2)
    return fC;
  else
    return fD;
}

//____________________________________________________________________
const Double_t& BrPlane3D::operator () (size_t i) const {
  if (i==0)
    return fA;
  else if (i == 1)
    return fB;
  else if (i == 2)
    return fC;
  else
    return fD;
}

//____________________________________________________________________
Double_t& BrPlane3D::operator () (size_t i) {
  if (i==0)
    return fA;
  else if (i == 1)
    return fB;
  else if (i == 2)
    return fC;
  else
    return fD;
}


//____________________________________________________________________
BrPlane3D & BrPlane3D::operator = (const BrPlane3D& plane){
  //
  // assignement operator
  //
  fA = plane.fA;
  fB = plane.fB;
  fC = plane.fC;
  fD = plane.fD;
  return *this;
}


//____________________________________________________________________
BrPlane3D operator+(const BrPlane3D& plane1, const BrPlane3D& plane2){
  //
  // The sum of two planes is one of two planes that is the divide 
  // the half between the two original planes. It happens to depend on the
  // (unspecified?) orientation of the plane normal vector (i.e) (fa,fb,fc)
  //
  BrPlane3D tmp;
  tmp.fA = plane1.fA + plane2.fA;
  tmp.fB = plane1.fB + plane2.fB;
  tmp.fC = plane1.fC + plane2.fC;
  tmp.fD = plane1.fD + plane2.fD;
  return tmp;
}

//____________________________________________________________________
BrPlane3D operator-(const BrPlane3D& plane1, const BrPlane3D& plane2){
  // The difference  of two planes is one of two planes that is the divide 
  // the half between the two original planes. It happens to depend on the
  // (unspecified?) orientation of the plane normal vector (i.e) (fa,fb,fc)
  // See also operator plus.
  //
  BrPlane3D tmp;
  tmp.fA = plane1.fA - plane2.fA;
  tmp.fB = plane1.fB - plane2.fB;
  tmp.fC = plane1.fC - plane2.fC;
  tmp.fD = plane1.fD - plane2.fD;
  return tmp;
}

//____________________________________________________________________
BrPlane3D& BrPlane3D::operator += (const BrPlane3D& plane){
  // See comment on sum
  fA += plane.fA;
  fB += plane.fB;
  fC += plane.fC;
  fD += plane.fD;
  return *this;
}

//____________________________________________________________________
BrPlane3D& BrPlane3D::operator -= (const BrPlane3D& plane){
  // See comment on difference
  fA -= plane.fA;
  fB -= plane.fB;
  fC -= plane.fC;
  fD -= plane.fD;
  return *this;
}

//____________________________________________________________________
BrPlane3D BrPlane3D::operator - () const{
  // change direction of normal vector for plane.
  //
  BrPlane3D tmp(-fA, -fB, -fC, -fD);
  return tmp;
}

//____________________________________________________________________
BrPlane3D BrPlane3D::operator + () const{
   return *this;
}

//____________________________________________________________________
Bool_t BrPlane3D::operator== (const BrPlane3D& plane2) const{
  // Boolean equal
  // This is not really the condition for two planes being equal
  // a) the normal vectors are same direction
  // b) the difference between the two points are normal to the
  // plane.
  //
  return ((fA == plane2.fA) && (fB == plane2.fB) && (fC == plane2.fC) && (fD == plane2.fD));
} 

//____________________________________________________________________
Bool_t BrPlane3D::operator!= (const BrPlane3D& plane2)const {
  // Boolean not equal
  return !(*this==plane2);
} 


//____________________________________________________________________
 void BrPlane3D::Set(const BrVector3D &p1, const BrVector3D &p2, 
		    const BrVector3D &p3)
{
  //Derive a plane from 3 points specified as point objects.
  
  fA = (p1[1] * (p2[2] - p3[2]) 
	+ p2[1] * (p3[2] - p1[2]) 
	+ p3[1] * (p1[2] - p2[2]));
  fB = (p1[2] * (p2[0] - p3[0]) 
	+ p2[2] * (p3[0] - p1[0]) 
	+ p3[2] * (p1[0] - p2[0]));
  fC = (p1[0] * (p2[1] - p3[1]) 
	+ p2[0] * (p3[1] - p1[1]) 
	+ p3[0] * (p1[1] - p2[1]));
  
  fD = - (p1[0] * (p2[1] * p3[2] - p3[1] * p2[2]) 
	  +  p2[0] * (p3[1] * p1[2] - p1[1] * p3[2]) 
	  +  p3[0] * (p1[1] * p2[2] - p2[1] * p1[2]));
}

//____________________________________________________________________
 BrVector3D BrPlane3D::GetIntersectionWithLine(const BrLine3D &line) 
{
  // Find the intersection of the specified line with this plane.
  // Must throw something if the line does not intercept.!!!
  //
  Double_t u;
  
  BrVector3D vhat = line.GetDirection().Unit();
  BrVector3D p1 = line.GetOrigin();
  
  u = - ( fA * p1[0]   + fB * p1[1]   + fC * p1[2]   + fD ) / 
    ( fA * vhat[0] + fB * vhat[1] + fC * vhat[2]      );
  
  return (p1 + u * vhat);
}

//____________________________________________________________________
 Double_t BrPlane3D::GetMinimumDistanceFromPlane(const BrVector3D &point) {
  //Get the minimum distance from the specified point to this plane
  Double_t dist;
  dist = (fA * point[0] + fB * point[1] + fC * point[2] + fD) / 
    TMath::Sqrt(fA*fA + fB*fB + fC*fC);
  return dist;
}

//____________________________________________________________________
 BrVector3D BrPlane3D::UnitNormal() {
  BrVector3D normal(fA,fB,fC);
return normal.Unit();
}


//____________________________________________________________________
//
//  friend global functions
//  =======================

//____________________________________________________________________
BrPlane3D operator*(Double_t a, const BrPlane3D& plane){
  //
  //  number multiply
  //
  BrPlane3D tmp;
  tmp.fA = a*plane.fA;
  tmp.fB = a*plane.fB;
  tmp.fC = a*plane.fC;
  tmp.fD = a*plane.fD;
  return tmp;
}

//____________________________________________________________________
BrPlane3D operator/(const BrPlane3D& plane, Double_t a){
  //
  //  number multiply
  //
  BrPlane3D tmp;
  tmp.fA = plane.fA / a;
  tmp.fB = plane.fB / a;
  tmp.fC = plane.fC / a;
  tmp.fD = plane.fD / a;
  return tmp;
}

//____________________________________________________________________
BrPlane3D operator*(const BrPlane3D& plane, Double_t a){
  //
  //  number multiply
  //
  BrPlane3D tmp;
  tmp.fA = a*plane.fA;
  tmp.fB = a*plane.fB;
  tmp.fC = a*plane.fC;
  tmp.fD = a*plane.fD;
  return tmp;
}

//____________________________________________________________________
//
// Related Functions (global non-member functions)
//

//____________________________________________________________________
ostream& operator<<(ostream& os, const BrPlane3D& plane){
  //
  // Write in default layout
  //
  os << "(" << plane.GetA() << ", "<< plane.GetB() << ", " << plane.GetC() << ", " << plane.GetD() << ")";
  return os; 
}

//____________________________________________________________________
istream& operator>>(istream& is, BrPlane3D& plane){
  //
  // Input stream operator
  //
  Double_t a, b, c, d;
  is >> a >> b >> c >> d;
  plane.SetA(a);
  plane.SetB(b);
  plane.SetC(c);
  plane.SetD(d);
  return is;
}

//____________________________________________________________________
//  $Log: BrPlane3D.cxx,v $
//  Revision 1.2  2001/07/19 18:11:14  ekman
//  Added  method to set (after initialisation) from 3 vectors.
//
//  Revision 1.1.1.1  2001/06/21 14:55:20  hagel
//  Initial revision of brat2
//
//  Revision 1.9  2001/04/30 21:17:17  videbaek
//  Added method to create Plane3D from a point and a normal vector.
//  Considered removing the add, divide which have a marginal precise definition.
//
//  Revision 1.8  1999/03/07 00:00:44  hagel
//  1. Implemented  BrFSTrackingModule.  Started with BrMRSTrackingModule and made
//     appropriate changes to handle the forward spectrometer.  It uses the new
//     track classes as well as extensively using geometry classes.  It also uses
//     new methods and functionality as described below.
//  2. Changed BrMagnetVolume
//     a.  Added method SwimBack(BrLine3D &,Double_t momentum): takes a
//         track at the exit of  magnet and given the momentum, calculates
//         where the track would come into the front of the magnet.
//     b.  Added method GlobalToLocal(BrLine3D &): does a combination of
//         GlobalToLocal(BrVector3D &,BrVector3D&,0) and
//         GlobalToLocal(BrVector3D &,BrVector3D&,1)
//     c.  Added method LocalToGlobal(BrLine3D &): does a combination of
//         LocalToGlobal(BrVector3D &,BrVector3D&,0) and
//         LocalToGlobal(BrVector3D &,BrVector3D&,1)
//     d.  Changed BrDetectorVolume: same additions of methods GlobalToLocal
//         and LocalToGlobal as in BrMagnetVolume
//  2.  Added a parameter base class BrDetectorParamsBase: helps when reading
//      in database files.  Declared ASCII reading routines to be virtual.
//      Has main ReadASCIIFile which decodes the ASCII parameter files, then
//      calls the detector specific methods SetASCIIParameter
//  3.  Implemented SetASCIIParameter in BrDetectorParamsDC, BrDetectorParamsTPC,
//      BrDetectorParamsTof, BrDetectorParamsBB
//  4.  Implemented BrParameterDbManager.  It currently works similarly to
//      BrGeometryDbManager and creates the BrDetectorParamsXXX objects when
//      called.  These objects then read in ASCII parameter files with a currently
//      "well defined" format using the above implemented routines using a constructor:
//      BrDetectorParamsXXX(Char_t *name, Char_t *title,Char_t *ASCIIFileName);
//  5.  If no parameter file is specified, it executes the constructor we
//      have been using so far, namely BrDetectorParamsXXX(Char_t *name,Char_t *title).
//      These constructors generate default parameters and are semi-intelligent
//      which means they generate approximately appropriate parameters depending
//      upon which detector they are.  I should say that the parameters were
//      deemed appropriate at the time of writing the SetDefaultParams routine.
//      a. It is used in the same way as BrGeometryDbManager, that is:
//         BrParameterDbManager *gParamDb = BrParameterDbManager::Instance();
//         gParamDb->SetDbParameterFileName("DetectorParameters.txt");
//  6.  Added a new directory, params, in BRAT.  This directory has the file
//      DetectorParameters.txt in it.  If the BrParameterDbManager is started
//      and the DetectorParameter.txt file is specified, it will look in the
//      $BRATSYS/params directory if it cannot find the file in the directory
//      that the user has set default to.
//  7.  Implemented BrParameterDbManager in DC digitize and tracking code.  The
//      SetDetectorParams methods have been moved to private and can no longer be
//      used from the macro or program.
//  8.  Implemented BrParameterDbManager in TPC digitize and tracking code.
//  9.  Implemented BrParameterDbManager in Tof Calibrate and GeneratePid code.
//  10  Changed the GetEntries() in BrDataTable to use the GetLast()+1 method in
//      TObjArray.  This should be much faster, but has the caveat that it assumes
//      that all slots in TObjArray are full.  That seems to me to be the case
//      in how we use TObjArray at least in BrDataTable, but if problems arise due
//      to this change, it can always be easily changed back.  It has been used a
//      fair amount before checking in and no problems were found.
//
//   Modified Files:
//   	base/inc/BrBase_LinkDef.h base/inc/BrDataTable.h
//   	base/inc/BrDetectorVolume.h base/inc/BrMagnetVolume.h
//   	base/inc/LinkDefBratBaseINC.h base/src/BrDataTable.cxx
//   	base/src/BrDetectorVolume.cxx base/src/BrEventNode.cxx
//   	base/src/BrMagnetVolume.cxx base/src/BrTableManager.cxx
//   	base/src/Makefile bb/inc/BrDetectorParamsBB.h
//   	bb/src/BrDetectorParamsBB.cxx db/inc/BrParameterDbManager.h
//   	db/src/BrParameterDbManager.cxx dc/inc/BrDetectorParamsDC.h
//   	dc/src/BrDetectorDC.cxx dc/src/BrDetectorParamsDC.cxx
//   	dc/src/BrDigitizeDC.cxx dc/src/BrLocalTrackDC.cxx
//   	geometry/inc/BrPlane3D.h geometry/src/BrPlane3D.cxx
//   	params/DetectorParameters.txt tof/inc/BrDetectorParamsTof.h
//   	tof/src/BrDetectorParamsTof.cxx tof/src/BrGeneratePid.cxx
//   	tpc/inc/BrDetectorParamsTPC.h tpc/src/BrDetectorParamsTPC.cxx
//   	tpc/src/BrDetectorTPC.cxx tpc/src/BrDigitizeTPC.cxx
//   	tpc/src/BrLocalTrackTPC.cxx track/inc/BrDetectorTrack.h
//   	track/inc/BrFSTrackingModule.h
//   	track/inc/BrSpectrometerTracks.h track/src/BrDetectorTrack.cxx
//   	track/src/BrFSTrackingModule.cxx
//   	track/src/BrSpectrometerTracks.cxx
//
//  Revision 1.7  1999/02/19 21:33:48  bearden
//  There was a minor error in the calculation of a plane, this has been corrected.  See comments in code for details.
//
//  Revision 1.6  1998/12/18 19:37:14  hagel
//  Implement UnitNormal
//
//  Revision 1.5  1998/12/18 17:21:55  hagel
//  Implement minimum distance from point to plane plus add comments
//
//  Revision 1.4  1998/12/17 21:16:12  hagel
//  Add CVS comments

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS