Skip to content

Commit

Permalink
Better code & add'l overload for THaSpectrometerDetector::CalcTrackIn…
Browse files Browse the repository at this point in the history
…tercept
  • Loading branch information
hansenjo committed Jan 23, 2018
1 parent b884ef8 commit c6ca74e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 30 deletions.
71 changes: 48 additions & 23 deletions src/THaSpectrometerDetector.C
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,72 @@ THaSpectrometerDetector::~THaSpectrometerDetector()
}

//_____________________________________________________________________________
bool THaSpectrometerDetector::CalcTrackIntercept(THaTrack* theTrack,
Double_t& t, Double_t& xcross,
Double_t& ycross)
Bool_t THaSpectrometerDetector::CalcTrackIntercept( THaTrack* theTrack,
TVector3& icept,
Double_t& pathl )
{
// projects a given track on to the plane of the detector
// xcross and ycross are the x and y coords of this intersection
// t is the distance from the origin of the track to the given plane.
// Find intercept coordinates of given track with the plane of
// this detector. Results are in 'icept' and 'pathl'
//
// If a hit is NOT found, then t, xcross, and ycross are unchanged.
// icept: Vector to track crossing point in track coordinate system
// pathl: pathlength from track origin (in the track coordinate system)
// to intersection point (m). This is identical to the length
// of the vector icept-t0

TVector3 t0( theTrack->GetX(), theTrack->GetY(), 0.0 );
Double_t norm = TMath::Sqrt(1.0 + theTrack->GetTheta()*theTrack->GetTheta() +
theTrack->GetPhi()*theTrack->GetPhi());
TVector3 t_hat( theTrack->GetTheta()/norm, theTrack->GetPhi()/norm, 1.0/norm );
TVector3 td( theTrack->GetTheta(), theTrack->GetPhi(), 1.0 );
td = td.Unit();

TVector3 v;
if( !IntersectPlaneWithRay( fXax, fYax, fOrigin, t0, t_hat, t, v ))
return false;
v -= fOrigin;
xcross = v.Dot(fXax);
ycross = v.Dot(fYax);
return IntersectPlaneWithRay( fXax, fYax, fOrigin, t0, td, pathl, icept );
}

//_____________________________________________________________________________
Bool_t THaSpectrometerDetector::CalcTrackIntercept( THaTrack* theTrack,
Double_t& pathl,
Double_t& xdet,
Double_t& ydet )
{
// Find intercept coordinates of given track with the plane of
// this detector. Results are in xdet, ydet and pathl.
//
// pathl: pathlength from track origin (in the track coordinate system)
// to intersection point (m). This is identical to the length
// of the vector icept-track_origin
// xdet: x-coordinate of intercept in detector coordinate system (m)
// ydet: y-coordinate of intercept in detector coordinate system (m)

// Does not check if the intercept coordinates are actually within
// the active area of the detector; use IsInActiveArea(val[1],val[2])
// to find out.

TVector3 icept;
if( !CalcTrackIntercept(theTrack, icept, pathl) )
return false;
TVector3 v = TrackToDetCoord(icept);
xdet = v.X();
ydet = v.Y();
return true;
}

//_____________________________________________________________________________
bool THaSpectrometerDetector::CheckIntercept(THaTrack *track)
Bool_t THaSpectrometerDetector::CheckIntercept( THaTrack *track )
{
Double_t x, y, t;
return CalcTrackIntercept(track, t, x, y);
TVector3 icept;
Double_t t;
return CalcTrackIntercept(track, icept, t);
}

//_____________________________________________________________________________
bool THaSpectrometerDetector::CalcInterceptCoords(THaTrack* track, Double_t& x, Double_t& y)
Bool_t THaSpectrometerDetector::CalcInterceptCoords( THaTrack* track,
Double_t& x, Double_t& y)
{
Double_t t;
return CalcTrackIntercept(track, t, x, y);
}

//_____________________________________________________________________________
bool THaSpectrometerDetector::CalcPathLen(THaTrack* track, Double_t& t)
Bool_t THaSpectrometerDetector::CalcPathLen( THaTrack* track, Double_t& t )
{
Double_t x, y;
return CalcTrackIntercept(track, t, x, y);
TVector3 icept;
return CalcTrackIntercept(track, icept, t);
}
15 changes: 8 additions & 7 deletions src/THaSpectrometerDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "THaDetector.h"

class THaTrack;
class TVector3;

class THaSpectrometerDetector : public THaDetector {

Expand All @@ -24,18 +25,18 @@ class THaSpectrometerDetector : public THaDetector {
virtual Bool_t IsTracking() = 0;
virtual Bool_t IsPid() = 0;

bool CheckIntercept( THaTrack* track );
bool CalcInterceptCoords( THaTrack* track,
Bool_t CheckIntercept( THaTrack* track );
Bool_t CalcInterceptCoords( THaTrack* track,
Double_t& x, Double_t& y );
bool CalcPathLen( THaTrack* track, Double_t& t );
Bool_t CalcPathLen( THaTrack* track, Double_t& t );
Bool_t CalcTrackIntercept( THaTrack* track, TVector3& icept,
Double_t& pathl );
Bool_t CalcTrackIntercept( THaTrack* track, Double_t& pathl,
Double_t& xdet, Double_t& ydet );

THaSpectrometerDetector(); // for ROOT I/O only

protected:

bool CalcTrackIntercept( THaTrack* track, Double_t& t,
Double_t& ycross, Double_t& xcross);

//Only derived classes may construct me
THaSpectrometerDetector( const char* name, const char* description,
THaApparatus* a = NULL );
Expand Down

0 comments on commit c6ca74e

Please sign in to comment.