//  $Id: BrGeantTrack.cxx,v 1.4 1998/07/28 21:31:01 videbaek Exp $
//  $Log: BrGeantTrack.cxx,v $
//  Revision 1.4  1998/07/28 21:31:01  videbaek
//  Change units to MeV
//
//  Revision 1.3  1998/04/30 17:12:35  videbaek
//  Added functionality to BrGeantInput
//
//  Revision 1.2  1998/03/09 20:54:19  videbaek
//  Ensure that pointers are non-NULL before deleting
//
//  Revision 1.1.1.1  1998/03/04 21:33:10  brahmlib
//  Brat geant
//
//
#include "math.h"
#include "iostream.h"

#include "BrGeantTrack.h"

class BrGeantHit;

ClassImp(BrGeantTrack)

/////////////////////////////////////////////////////////////////
//
// BrGeantTrack is a BRAHMS data class providing access to momentum,
// PID and hit information for a single GBRAHMS track.
//
/////////////////////////////////////////////////////////////////

  BrGeantTrack::BrGeantTrack()
{
// Constructor. Reset all variables as well as fHitList to NULL.
//
    fHitList = NULL;
    fVx = 0;
    fVy = 0;
    fVz = 0;
    fMass = 0;
    fPx = 0;
    fPy = 0;
    fPz = 0;
    fPid = 0;
    fHitCounter = 0;
}

  BrGeantTrack::BrGeantTrack(GeantStreamTracks& ffTracks)
{
// Constructor. Set fHitList to NULL.
//  Fill all relevant vriables with those read from the
//  stream file.
//
    fHitList = NULL;
    fVx      = ffTracks.vert[0];
    fVy      = ffTracks.vert[1];
    fVz      = ffTracks.vert[2];
    // Need to insert mass (geantPid->Mass)
    fMass    = 0;
    fCharge  = ffTracks.charge;
    // convert to MeV
    fPx      = ffTracks.pvert[0] * 1.0e3;
    fPy      = ffTracks.pvert[1] * 1.0e3;
    fPz      = ffTracks.pvert[2] * 1.0e3;
    fPid     = ffTracks.pid;
    fNtbeam  = ffTracks.ntbeam;
    fTrackno = ffTracks.trackno;
    fHitCounter = 0;
}

  BrGeantTrack::~BrGeantTrack()
{

// Destructor. Clears fHitList if applicable, but does
// not delete BrGeantHit objects.

  if(fHitList){
    fHitList->Clear();
    delete fHitList;
  }

//mpd delete polyline
//    if(fPolyLine)
//      delete fPolyLine;
}

  void BrGeantTrack::AddHit(BrGeantHit *hit)
{
// Add one hit to fHitList, create fHitList if necessary.
// Used only when event display is enabled. Not for normal tracking
//  purposes.

  if(!fHitList)
    fHitList = new TObjArray();
  fHitList->Add(hit);
}

  void BrGeantTrack::MakeHitList()
{
// Create fHitList if necessary.

    if(!fHitList)
        fHitList = new TObjArray();
}

  Int_t BrGeantTrack::NHits()
{
// Get number of hits on the track if applicable

    if(fHitList)
        return fHitList->GetEntries();
    else
        return 0;
}

  Double_t  BrGeantTrack::Energy()
{
// return track energy, assuming mass fMass.
//
    return sqrt(Px()*Px()+Py()*Py()+Pz()*Pz()+fMass*fMass);
}

 Double_t  BrGeantTrack::P()
{
// return track energy, assuming mass fMass.
//
    return sqrt(Px()*Px()+Py()*Py()+Pz()*Pz()+fMass*fMass);
}
 
 Double_t BrGeantTrack::Rap(Double_t mass)
{
// return track energy, assuming mass given in argument.
//
    Double_t rap;
    Double_t E;

    E = sqrt(mass*mass + Pz()*Pz()+Px()*Px()+Py()*Py());
    rap = 0.5 * log((E+Pz())/(E-Pz()));

    return rap;
}

  Double_t BrGeantTrack::Theta()
{
// Calculate polar angle in radians for track.
   if(Pz()==0)
      return 0;
   else
      return atan(Px()/Pz());
}

  Double_t BrGeantTrack::Dip()
{
   if(Pz()==0)
      return 0;
   else
      return atan(Py()/Pz());
}

  Double_t BrGeantTrack::Beta()
{
// velocity of track in v/c;
//
    Double_t p;
    Double_t E;

    p = P();
    E = sqrt(p*p + fMass* fMass); 
    return p/E;
}

  BrGeantHit *BrGeantTrack::NextHit()
{
// Iterator over hits on track. Note that this loop
// can NOT be nested. Use the GetHitList() call to
// obtain and manipulate the fHitList ObjArray for 
// more complicated loops.
    
    if(fHitList)
    {
        return (BrGeantHit *) fHitList->At(fHitCounter++);
    }
    else
    {
        return NULL;
    }
}

/*
 void BrGeantTrack::Draw(Int_t color)
{
// Draw the track. Note that this function is not standalone,
// but should be used in a context as provided by the 
// TPhDetector::Draw() member function

    Int_t   num;
    BrGeantHit *hit;

    if(fHitList)
    {
        if(!fPolyLine)
        {
            fPolyLine = new TPolyLine3D(GetNHits()+1);
            fPolyLine->SetPoint(0,0,0,0); 
            num = 1;
            ResetHitCounter();
            while(hit = GetNextHit())
            {
//                fPolyLine->SetPoint(num,hit->GetX(),hit->GetY(),hit->GetZ()); 
                num++;
            }
        }
        fPolyLine->SetLineColor(color);
        fPolyLine->Draw();
    }
}

*/
  void BrGeantTrack::ListHits()
{
//
// List hits attached to this track hitlist.
//
      if(fHitList)
      {
          TIter NextHit(fHitList);
          BrGeantHit *hit;
          while(hit = (BrGeantHit *) NextHit())
          {
/*              printf("Hit in plane %d at %g %g %g with energy %gn",
                          hit->GetLayer(),
                          hit->GetX(),
                          hit->GetY(),
                          hit->GetZ(),
                          hit->GetEnergy());
						  */
          }
      }
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.