Logo ROOT   6.08/07
Reference Guide
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 "TGeoManager.h"
13 
14 #include "TVirtualGeoTrack.h"
15 
16 /** \class TVirtualGeoTrack
17 \ingroup Geometry_classes
18 
19 Base class for user-defined tracks attached to a geometry.
20 Tracks are 3D objects made of points and they store a
21 pointer to a TParticle. The geometry manager holds a list
22 of all tracks that will be deleted on destruction of
23 gGeoManager.
24 */
25 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Virtual tracks default constructor
30 
32 {
33  fPDG = 0;
34  fId = -1;
35  fParent = 0;
36  fParticle = 0;
37  fTracks = 0;
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Constructor providing ID for parent track (-1 for primaries), ID of this
42 /// track and related particle pointer.
43 
45 {
46  fPDG = pdgcode;
47  fId = id;
48  fParent = parent;
49  fParticle = particle;
50  fTracks = 0;
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Copy ctor. NOT TO BE CALLED.
55 
57  :TObject(other), TGeoAtt(other), TAttLine(other), TAttMarker(other),
58  fPDG(other.fPDG),
59  fId(other.fId),
60  fParent(other.fParent),
61  fParticle(other.fParticle),
62  fTracks(other.fTracks)
63 {
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Assignment operator. NOT TO BE CALLED.
68 
70 {
71  if(this!=&gv) {
73  TGeoAtt::operator=(gv);
74  TAttLine::operator=(gv);
75  TAttMarker::operator=(gv);
76  fPDG=gv.fPDG;
77  fId=gv.fId;
78  fParent=gv.fParent;
80  fTracks=gv.fTracks;
81  }
82  return *this;
83 }
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Destructor.
87 
89 {
90  if (fTracks) {
91  fTracks->Delete();
92  delete fTracks;
93  }
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Returns daughter id.
98 
100 {
101  TVirtualGeoTrack *daughter = GetDaughter(index);
102  if (!daughter) {
103  Error("GetDaughterId", "No daughter track with index %d", index);
104  return -1;
105  }
106  return daughter->GetId();
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Recursively search through this track for a daughter
111 /// particle (at any depth) with the specified id
112 
114 {
115  TVirtualGeoTrack* trk=0;
116  if (GetId()==id) {
117  trk = (TVirtualGeoTrack*)this;
118  return trk;
119  }
120  TVirtualGeoTrack* kid=0;
121  Int_t nd = GetNdaughters();
122  for (Int_t i=0; i<nd; i++) if (GetDaughterId(i) == id) return GetDaughter(i);
123  for (Int_t i=0; i<nd; i++) {
124  kid = GetDaughter(i);
125  if (kid!=0) {
126  trk = kid->FindTrackWithId(id);
127  if (trk!=0) break;
128  }
129  }
130  return trk;
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Get the PDG name.
135 
136 const char *TVirtualGeoTrack::GetName() const
137 {
138  return gGeoManager->GetPdgName(fPDG);
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// True if track TOF range overlaps with time interval of TGeoManager
143 
145 {
146  Double_t tmin, tmax;
147  Bool_t timecut = gGeoManager->GetTminTmax(tmin,tmax);
148  if (!timecut) return kTRUE;
149  const Double_t *point = GetFirstPoint();
150  if (!point) return kFALSE;
151  if (point[3]>tmax) return kFALSE;
152  point = GetLastPoint();
153  if (point[3]<tmin) return kFALSE;
154  return kTRUE;
155 }
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 /// Set a default name for this track.
159 
161 {
162  gGeoManager->SetPdgName(fPDG, name);
163  if (!strcmp(name, "gamma")) {
166  SetLineWidth(1);
168  return;
169  }
170  if (!strcmp(name, "pi+") || !strcmp(name, "proton") || !strcmp(name, "K+")) {
173  SetLineWidth(2);
174  return;
175  }
176  if (!strcmp(name, "pi-") || !strcmp(name, "K-")) {
177  SetLineColor(30);
178  SetMarkerColor(30);
179  SetLineWidth(2);
180  return;
181  }
182  if (!strcmp(name, "pi0") || !strcmp(name, "K0")) {
185  SetLineWidth(2);
186  return;
187  }
188  if (!strcmp(name, "neutron")) {
189  SetLineColor(16);
190  SetMarkerColor(16);
191  SetLineWidth(1);
193  return;
194  }
195  if (!strcmp(name, "Alpha") || !strcmp(name, "Deuteron") || !strcmp(name, "Triton")) {
198  SetLineWidth(3);
199  return;
200  }
201  if (!strcmp(name, "e-") || !strcmp(name, "mu-")) {
204  SetLineWidth(1);
206  return;
207  }
208  if (!strcmp(name, "e+") || !strcmp(name, "mu+")) {
211  SetLineWidth(1);
213  return;
214  }
215 }
216 
217 
const Double_t * GetLastPoint() const
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:49
Bool_t GetTminTmax(Double_t &tmin, Double_t &tmax) const
Get time cut for drawing tracks.
virtual const char * GetName() const
Get the PDG name.
virtual Int_t GetDaughterId(Int_t index) const
Returns daughter id.
Bool_t IsInTimeRange() const
True if track TOF range overlaps with time interval of TGeoManager.
Visualization and tracking attributes for volumes and nodes.
Definition: TGeoAtt.h:19
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:329
Definition: Rtypes.h:61
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Definition: Rtypes.h:61
Int_t GetId() const
const char * GetPdgName(Int_t pdg) const
Get name for given pdg code;.
Marker Attributes class.
Definition: TAttMarker.h:24
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:43
virtual TVirtualGeoTrack * FindTrackWithId(Int_t id) const
Recursively search through this track for a daughter particle (at any depth) with the specified id...
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:103
Base class for user-defined tracks attached to a geometry.
XFontStruct * id
Definition: TGX11.cxx:108
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
void SetPdgName(Int_t pdg, const char *name)
Set a name for a particle having a given pdg.
void SetName(const char *name)
Set a default name for this track.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
TVirtualGeoTrack * GetDaughter(Int_t index) const
#define ClassImp(name)
Definition: Rtypes.h:279
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:554
double Double_t
Definition: RtypesCore.h:55
TVirtualGeoTrack & operator=(const TVirtualGeoTrack &)
Assignment operator. NOT TO BE CALLED.
Definition: Rtypes.h:61
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:48
const Double_t * GetFirstPoint() const
Mother of all ROOT objects.
Definition: TObject.h:37
TVirtualGeoTrack()
Virtual tracks default constructor.
TObjArray * fTracks
Definition: Rtypes.h:61
Int_t GetNdaughters() const
const Bool_t kTRUE
Definition: Rtypes.h:91
TVirtualGeoTrack * fParent
Line Attributes class.
Definition: TAttLine.h:24
char name[80]
Definition: TGX11.cxx:109
virtual ~TVirtualGeoTrack()
Destructor.