Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TVirtualGeoTrack.cxx
Go to the documentation of this file.
1 // @(#)root/geom:$Id$
2 // Author: Andrei Gheata 2003/04/10
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TVirtualGeoTrack.h"
13 
14 #include "Rtypes.h"
15 #include "TGeoManager.h"
16 #include "TObject.h"
17 
18 /** \class TVirtualGeoTrack
19 \ingroup Geometry_classes
20 
21 Base class for user-defined tracks attached to a geometry.
22 Tracks are 3D objects made of points and they store a
23 pointer to a TParticle. The geometry manager holds a list
24 of all tracks that will be deleted on destruction of
25 gGeoManager.
26 */
27 
28 ClassImp(TVirtualGeoTrack);
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Virtual tracks default constructor
32 
33 TVirtualGeoTrack::TVirtualGeoTrack()
34 {
35  fPDG = 0;
36  fId = -1;
37  fParent = 0;
38  fParticle = 0;
39  fTracks = 0;
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Constructor providing ID for parent track (-1 for primaries), ID of this
44 /// track and related particle pointer.
45 
46 TVirtualGeoTrack::TVirtualGeoTrack(Int_t id, Int_t pdgcode, TVirtualGeoTrack *parent, TObject *particle)
47 {
48  fPDG = pdgcode;
49  fId = id;
50  fParent = parent;
51  fParticle = particle;
52  fTracks = 0;
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Copy ctor. NOT TO BE CALLED.
57 
58 TVirtualGeoTrack::TVirtualGeoTrack(const TVirtualGeoTrack& other)
59  :TObject(other), TGeoAtt(other), TAttLine(other), TAttMarker(other),
60  fPDG(other.fPDG),
61  fId(other.fId),
62  fParent(other.fParent),
63  fParticle(other.fParticle),
64  fTracks(other.fTracks)
65 {
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Assignment operator. NOT TO BE CALLED.
70 
71 TVirtualGeoTrack& TVirtualGeoTrack::operator=(const TVirtualGeoTrack& gv)
72 {
73  if(this!=&gv) {
74  TObject::operator=(gv);
75  TGeoAtt::operator=(gv);
76  TAttLine::operator=(gv);
77  TAttMarker::operator=(gv);
78  fPDG=gv.fPDG;
79  fId=gv.fId;
80  fParent=gv.fParent;
81  fParticle=gv.fParticle;
82  fTracks=gv.fTracks;
83  }
84  return *this;
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Destructor.
89 
90 TVirtualGeoTrack::~TVirtualGeoTrack()
91 {
92  if (fTracks) {
93  fTracks->Delete();
94  delete fTracks;
95  }
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Returns daughter id.
100 
101 Int_t TVirtualGeoTrack::GetDaughterId(Int_t index) const
102 {
103  TVirtualGeoTrack *daughter = GetDaughter(index);
104  if (!daughter) {
105  Error("GetDaughterId", "No daughter track with index %d", index);
106  return -1;
107  }
108  return daughter->GetId();
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Recursively search through this track for a daughter
113 /// particle (at any depth) with the specified id
114 
115 TVirtualGeoTrack *TVirtualGeoTrack::FindTrackWithId(Int_t id) const
116 {
117  TVirtualGeoTrack* trk=0;
118  if (GetId()==id) {
119  trk = (TVirtualGeoTrack*)this;
120  return trk;
121  }
122  TVirtualGeoTrack* kid=0;
123  Int_t nd = GetNdaughters();
124  for (Int_t i=0; i<nd; i++) if (GetDaughterId(i) == id) return GetDaughter(i);
125  for (Int_t i=0; i<nd; i++) {
126  kid = GetDaughter(i);
127  if (kid!=0) {
128  trk = kid->FindTrackWithId(id);
129  if (trk!=0) break;
130  }
131  }
132  return trk;
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Get the PDG name.
137 
138 const char *TVirtualGeoTrack::GetName() const
139 {
140  return gGeoManager->GetPdgName(fPDG);
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// True if track TOF range overlaps with time interval of TGeoManager
145 
146 Bool_t TVirtualGeoTrack::IsInTimeRange() const
147 {
148  Double_t tmin, tmax;
149  Bool_t timecut = gGeoManager->GetTminTmax(tmin,tmax);
150  if (!timecut) return kTRUE;
151  const Double_t *point = GetFirstPoint();
152  if (!point) return kFALSE;
153  if (point[3]>tmax) return kFALSE;
154  point = GetLastPoint();
155  if (point[3]<tmin) return kFALSE;
156  return kTRUE;
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Set a default name for this track.
161 
162 void TVirtualGeoTrack::SetName(const char *name)
163 {
164  gGeoManager->SetPdgName(fPDG, name);
165  if (!strcmp(name, "gamma")) {
166  SetLineColor(kGreen);
167  SetMarkerColor(kGreen);
168  SetLineWidth(1);
169  SetLineStyle(kDotted);
170  return;
171  }
172  if (!strcmp(name, "pi+") || !strcmp(name, "proton") || !strcmp(name, "K+")) {
173  SetLineColor(kRed);
174  SetMarkerColor(kRed);
175  SetLineWidth(2);
176  return;
177  }
178  if (!strcmp(name, "pi-") || !strcmp(name, "K-")) {
179  SetLineColor(30);
180  SetMarkerColor(30);
181  SetLineWidth(2);
182  return;
183  }
184  if (!strcmp(name, "pi0") || !strcmp(name, "K0")) {
185  SetLineColor(kCyan);
186  SetMarkerColor(kCyan);
187  SetLineWidth(2);
188  return;
189  }
190  if (!strcmp(name, "neutron")) {
191  SetLineColor(16);
192  SetMarkerColor(16);
193  SetLineWidth(1);
194  SetLineStyle(kDotted);
195  return;
196  }
197  if (!strcmp(name, "Alpha") || !strcmp(name, "Deuteron") || !strcmp(name, "Triton")) {
198  SetLineColor(kMagenta);
199  SetMarkerColor(kMagenta);
200  SetLineWidth(3);
201  return;
202  }
203  if (!strcmp(name, "e-") || !strcmp(name, "mu-")) {
204  SetLineColor(kBlue);
205  SetMarkerColor(kBlue);
206  SetLineWidth(1);
207  SetLineStyle(kDotted);
208  return;
209  }
210  if (!strcmp(name, "e+") || !strcmp(name, "mu+")) {
211  SetLineColor(kMagenta);
212  SetMarkerColor(kMagenta);
213  SetLineWidth(1);
214  SetLineStyle(kDotted);
215  return;
216  }
217 }
218 
219