// @(#)root/geom:$Id$
// Author: Andrei Gheata  2003/04/10

/*************************************************************************
 * Copyright (C) 1995-2000, 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 "TGeoManager.h"

#include "TVirtualGeoTrack.h"

//______________________________________________________________________________
// TVirtualGeoTrack - Base class for user-defined tracks attached to a geometry.
//             Tracks are 3D objects made of points and they store a
//             pointer to a TParticle. The geometry manager holds a list
//             of all tracks that will be deleted on destruction of
//             gGeoManager.
//
//______________________________________________________________________________

ClassImp(TVirtualGeoTrack)

//______________________________________________________________________________
TVirtualGeoTrack::TVirtualGeoTrack()
{
//*-*-*-*-*-*-*-*-*-*-*Virtual tracks default constructor*-*-*-*-*-*-*-*-*
//*-*                  ==================================
   fPDG        = 0;
   fId         = -1;
   fParent     = 0;
   fParticle   = 0;
   fTracks     = 0;
}

//______________________________________________________________________________
TVirtualGeoTrack::TVirtualGeoTrack(Int_t id, Int_t pdgcode, TVirtualGeoTrack *parent, TObject *particle)
{
// Constructor providing ID for parent track (-1 for primaries), ID of this
// track and related particle pointer.
   fPDG        = pdgcode;
   fId         = id;
   fParent     = parent;
   fParticle   = particle;
   fTracks     = 0;
}

//_____________________________________________________________________________
TVirtualGeoTrack::TVirtualGeoTrack(const TVirtualGeoTrack& other)
                 :TObject(other), TGeoAtt(other), TAttLine(other), TAttMarker(other),
                  fPDG(other.fPDG),
                  fId(other.fId),
                  fParent(other.fParent),
                  fParticle(other.fParticle),
                  fTracks(other.fTracks)
{
// Copy ctor. NOT TO BE CALLED.
}

//_____________________________________________________________________________
TVirtualGeoTrack& TVirtualGeoTrack::operator=(const TVirtualGeoTrack& gv)
{
   // Assignment operator. NOT TO BE CALLED.
   if(this!=&gv) {
      TObject::operator=(gv);
      TGeoAtt::operator=(gv);
      TAttLine::operator=(gv);
      TAttMarker::operator=(gv);
      fPDG=gv.fPDG;
      fId=gv.fId;
      fParent=gv.fParent;
      fParticle=gv.fParticle;
      fTracks=gv.fTracks;
   }
   return *this;
}

//______________________________________________________________________________
TVirtualGeoTrack::~TVirtualGeoTrack()
{
// Destructor.
   if (fTracks) {
      fTracks->Delete();
      delete fTracks;
   }
}

//______________________________________________________________________________
Int_t TVirtualGeoTrack::GetDaughterId(Int_t index) const
{
// Returns daughter id.
   TVirtualGeoTrack *daughter = GetDaughter(index);
   if (!daughter) {
      Error("GetDaughterId", "No daughter track with index %d", index);
      return -1;
   }
   return daughter->GetId();
}

//______________________________________________________________________________
TVirtualGeoTrack *TVirtualGeoTrack::FindTrackWithId(Int_t id) const
{
// Recursively search through this track for a daughter
// particle (at any depth) with the specified id
   TVirtualGeoTrack* trk=0;
   if (GetId()==id) {
      trk = (TVirtualGeoTrack*)this;
      return trk;
   }
   TVirtualGeoTrack* kid=0;
   Int_t nd = GetNdaughters();
   for (Int_t i=0; i<nd; i++) if (GetDaughterId(i) == id) return GetDaughter(i);
   for (Int_t i=0; i<nd; i++) {
      kid = GetDaughter(i);
      if (kid!=0) {
         trk = kid->FindTrackWithId(id);
         if (trk!=0) break;
      }
   }
   return trk;
}

//______________________________________________________________________________
const char *TVirtualGeoTrack::GetName() const
{
// Get the PDG name.
   return gGeoManager->GetPdgName(fPDG);
}

//______________________________________________________________________________
Bool_t TVirtualGeoTrack::IsInTimeRange() const
{
// True if track TOF range overlaps with time interval of TGeoManager
   Double_t tmin, tmax;
   Bool_t timecut = gGeoManager->GetTminTmax(tmin,tmax);
   if (!timecut) return kTRUE;
   const Double_t *point = GetFirstPoint();
   if (!point) return kFALSE;
   if (point[3]>tmax) return kFALSE;
   point = GetLastPoint();
   if (point[3]<tmin) return kFALSE;
   return kTRUE;
}

//______________________________________________________________________________
void TVirtualGeoTrack::SetName(const char *name)
{
// Set a default name for this track.
   gGeoManager->SetPdgName(fPDG, name);
   if (!strcmp(name, "gamma")) {
      SetLineColor(kGreen);
      SetMarkerColor(kGreen);
      SetLineWidth(1);
      SetLineStyle(kDotted);
      return;
   }
   if (!strcmp(name, "pi+") || !strcmp(name, "proton") || !strcmp(name, "K+")) {
      SetLineColor(kRed);
      SetMarkerColor(kRed);
      SetLineWidth(2);
      return;
   }
   if (!strcmp(name, "pi-") || !strcmp(name, "K-")) {
      SetLineColor(30);
      SetMarkerColor(30);
      SetLineWidth(2);
      return;
   }
   if (!strcmp(name, "pi0") || !strcmp(name, "K0")) {
      SetLineColor(kCyan);
      SetMarkerColor(kCyan);
      SetLineWidth(2);
      return;
   }
   if (!strcmp(name, "neutron")) {
      SetLineColor(16);
      SetMarkerColor(16);
      SetLineWidth(1);
      SetLineStyle(kDotted);
      return;
   }
   if (!strcmp(name, "Alpha") || !strcmp(name, "Deuteron") || !strcmp(name, "Triton")) {
      SetLineColor(kMagenta);
      SetMarkerColor(kMagenta);
      SetLineWidth(3);
      return;
   }
   if (!strcmp(name, "e-") || !strcmp(name, "mu-")) {
      SetLineColor(kBlue);
      SetMarkerColor(kBlue);
      SetLineWidth(1);
      SetLineStyle(kDotted);
      return;
   }
   if (!strcmp(name, "e+") || !strcmp(name, "mu+")) {
      SetLineColor(kMagenta);
      SetMarkerColor(kMagenta);
      SetLineWidth(1);
      SetLineStyle(kDotted);
      return;
   }
}


 TVirtualGeoTrack.cxx:1
 TVirtualGeoTrack.cxx:2
 TVirtualGeoTrack.cxx:3
 TVirtualGeoTrack.cxx:4
 TVirtualGeoTrack.cxx:5
 TVirtualGeoTrack.cxx:6
 TVirtualGeoTrack.cxx:7
 TVirtualGeoTrack.cxx:8
 TVirtualGeoTrack.cxx:9
 TVirtualGeoTrack.cxx:10
 TVirtualGeoTrack.cxx:11
 TVirtualGeoTrack.cxx:12
 TVirtualGeoTrack.cxx:13
 TVirtualGeoTrack.cxx:14
 TVirtualGeoTrack.cxx:15
 TVirtualGeoTrack.cxx:16
 TVirtualGeoTrack.cxx:17
 TVirtualGeoTrack.cxx:18
 TVirtualGeoTrack.cxx:19
 TVirtualGeoTrack.cxx:20
 TVirtualGeoTrack.cxx:21
 TVirtualGeoTrack.cxx:22
 TVirtualGeoTrack.cxx:23
 TVirtualGeoTrack.cxx:24
 TVirtualGeoTrack.cxx:25
 TVirtualGeoTrack.cxx:26
 TVirtualGeoTrack.cxx:27
 TVirtualGeoTrack.cxx:28
 TVirtualGeoTrack.cxx:29
 TVirtualGeoTrack.cxx:30
 TVirtualGeoTrack.cxx:31
 TVirtualGeoTrack.cxx:32
 TVirtualGeoTrack.cxx:33
 TVirtualGeoTrack.cxx:34
 TVirtualGeoTrack.cxx:35
 TVirtualGeoTrack.cxx:36
 TVirtualGeoTrack.cxx:37
 TVirtualGeoTrack.cxx:38
 TVirtualGeoTrack.cxx:39
 TVirtualGeoTrack.cxx:40
 TVirtualGeoTrack.cxx:41
 TVirtualGeoTrack.cxx:42
 TVirtualGeoTrack.cxx:43
 TVirtualGeoTrack.cxx:44
 TVirtualGeoTrack.cxx:45
 TVirtualGeoTrack.cxx:46
 TVirtualGeoTrack.cxx:47
 TVirtualGeoTrack.cxx:48
 TVirtualGeoTrack.cxx:49
 TVirtualGeoTrack.cxx:50
 TVirtualGeoTrack.cxx:51
 TVirtualGeoTrack.cxx:52
 TVirtualGeoTrack.cxx:53
 TVirtualGeoTrack.cxx:54
 TVirtualGeoTrack.cxx:55
 TVirtualGeoTrack.cxx:56
 TVirtualGeoTrack.cxx:57
 TVirtualGeoTrack.cxx:58
 TVirtualGeoTrack.cxx:59
 TVirtualGeoTrack.cxx:60
 TVirtualGeoTrack.cxx:61
 TVirtualGeoTrack.cxx:62
 TVirtualGeoTrack.cxx:63
 TVirtualGeoTrack.cxx:64
 TVirtualGeoTrack.cxx:65
 TVirtualGeoTrack.cxx:66
 TVirtualGeoTrack.cxx:67
 TVirtualGeoTrack.cxx:68
 TVirtualGeoTrack.cxx:69
 TVirtualGeoTrack.cxx:70
 TVirtualGeoTrack.cxx:71
 TVirtualGeoTrack.cxx:72
 TVirtualGeoTrack.cxx:73
 TVirtualGeoTrack.cxx:74
 TVirtualGeoTrack.cxx:75
 TVirtualGeoTrack.cxx:76
 TVirtualGeoTrack.cxx:77
 TVirtualGeoTrack.cxx:78
 TVirtualGeoTrack.cxx:79
 TVirtualGeoTrack.cxx:80
 TVirtualGeoTrack.cxx:81
 TVirtualGeoTrack.cxx:82
 TVirtualGeoTrack.cxx:83
 TVirtualGeoTrack.cxx:84
 TVirtualGeoTrack.cxx:85
 TVirtualGeoTrack.cxx:86
 TVirtualGeoTrack.cxx:87
 TVirtualGeoTrack.cxx:88
 TVirtualGeoTrack.cxx:89
 TVirtualGeoTrack.cxx:90
 TVirtualGeoTrack.cxx:91
 TVirtualGeoTrack.cxx:92
 TVirtualGeoTrack.cxx:93
 TVirtualGeoTrack.cxx:94
 TVirtualGeoTrack.cxx:95
 TVirtualGeoTrack.cxx:96
 TVirtualGeoTrack.cxx:97
 TVirtualGeoTrack.cxx:98
 TVirtualGeoTrack.cxx:99
 TVirtualGeoTrack.cxx:100
 TVirtualGeoTrack.cxx:101
 TVirtualGeoTrack.cxx:102
 TVirtualGeoTrack.cxx:103
 TVirtualGeoTrack.cxx:104
 TVirtualGeoTrack.cxx:105
 TVirtualGeoTrack.cxx:106
 TVirtualGeoTrack.cxx:107
 TVirtualGeoTrack.cxx:108
 TVirtualGeoTrack.cxx:109
 TVirtualGeoTrack.cxx:110
 TVirtualGeoTrack.cxx:111
 TVirtualGeoTrack.cxx:112
 TVirtualGeoTrack.cxx:113
 TVirtualGeoTrack.cxx:114
 TVirtualGeoTrack.cxx:115
 TVirtualGeoTrack.cxx:116
 TVirtualGeoTrack.cxx:117
 TVirtualGeoTrack.cxx:118
 TVirtualGeoTrack.cxx:119
 TVirtualGeoTrack.cxx:120
 TVirtualGeoTrack.cxx:121
 TVirtualGeoTrack.cxx:122
 TVirtualGeoTrack.cxx:123
 TVirtualGeoTrack.cxx:124
 TVirtualGeoTrack.cxx:125
 TVirtualGeoTrack.cxx:126
 TVirtualGeoTrack.cxx:127
 TVirtualGeoTrack.cxx:128
 TVirtualGeoTrack.cxx:129
 TVirtualGeoTrack.cxx:130
 TVirtualGeoTrack.cxx:131
 TVirtualGeoTrack.cxx:132
 TVirtualGeoTrack.cxx:133
 TVirtualGeoTrack.cxx:134
 TVirtualGeoTrack.cxx:135
 TVirtualGeoTrack.cxx:136
 TVirtualGeoTrack.cxx:137
 TVirtualGeoTrack.cxx:138
 TVirtualGeoTrack.cxx:139
 TVirtualGeoTrack.cxx:140
 TVirtualGeoTrack.cxx:141
 TVirtualGeoTrack.cxx:142
 TVirtualGeoTrack.cxx:143
 TVirtualGeoTrack.cxx:144
 TVirtualGeoTrack.cxx:145
 TVirtualGeoTrack.cxx:146
 TVirtualGeoTrack.cxx:147
 TVirtualGeoTrack.cxx:148
 TVirtualGeoTrack.cxx:149
 TVirtualGeoTrack.cxx:150
 TVirtualGeoTrack.cxx:151
 TVirtualGeoTrack.cxx:152
 TVirtualGeoTrack.cxx:153
 TVirtualGeoTrack.cxx:154
 TVirtualGeoTrack.cxx:155
 TVirtualGeoTrack.cxx:156
 TVirtualGeoTrack.cxx:157
 TVirtualGeoTrack.cxx:158
 TVirtualGeoTrack.cxx:159
 TVirtualGeoTrack.cxx:160
 TVirtualGeoTrack.cxx:161
 TVirtualGeoTrack.cxx:162
 TVirtualGeoTrack.cxx:163
 TVirtualGeoTrack.cxx:164
 TVirtualGeoTrack.cxx:165
 TVirtualGeoTrack.cxx:166
 TVirtualGeoTrack.cxx:167
 TVirtualGeoTrack.cxx:168
 TVirtualGeoTrack.cxx:169
 TVirtualGeoTrack.cxx:170
 TVirtualGeoTrack.cxx:171
 TVirtualGeoTrack.cxx:172
 TVirtualGeoTrack.cxx:173
 TVirtualGeoTrack.cxx:174
 TVirtualGeoTrack.cxx:175
 TVirtualGeoTrack.cxx:176
 TVirtualGeoTrack.cxx:177
 TVirtualGeoTrack.cxx:178
 TVirtualGeoTrack.cxx:179
 TVirtualGeoTrack.cxx:180
 TVirtualGeoTrack.cxx:181
 TVirtualGeoTrack.cxx:182
 TVirtualGeoTrack.cxx:183
 TVirtualGeoTrack.cxx:184
 TVirtualGeoTrack.cxx:185
 TVirtualGeoTrack.cxx:186
 TVirtualGeoTrack.cxx:187
 TVirtualGeoTrack.cxx:188
 TVirtualGeoTrack.cxx:189
 TVirtualGeoTrack.cxx:190
 TVirtualGeoTrack.cxx:191
 TVirtualGeoTrack.cxx:192
 TVirtualGeoTrack.cxx:193
 TVirtualGeoTrack.cxx:194
 TVirtualGeoTrack.cxx:195
 TVirtualGeoTrack.cxx:196
 TVirtualGeoTrack.cxx:197
 TVirtualGeoTrack.cxx:198
 TVirtualGeoTrack.cxx:199
 TVirtualGeoTrack.cxx:200
 TVirtualGeoTrack.cxx:201
 TVirtualGeoTrack.cxx:202
 TVirtualGeoTrack.cxx:203
 TVirtualGeoTrack.cxx:204
 TVirtualGeoTrack.cxx:205
 TVirtualGeoTrack.cxx:206
 TVirtualGeoTrack.cxx:207