Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TPrimary.cxx
Go to the documentation of this file.
1 // @(#)root/eg:$Id$
2 // Author: Ola Nordmann 21/09/95
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 /** \class TPrimary
13  \ingroup eg
14 
15 Old version of a dynamic particle class created by event generators.
16 
17 This class is now obsolete. Use TParticle instead.
18 */
19 
20 #include "TObject.h"
21 #include "Rtypes.h"
22 #include "TString.h"
23 #include "TAttParticle.h"
24 #include "TPrimary.h"
25 #include "TView.h"
26 #include "TMath.h"
27 #include "TVirtualPad.h"
28 #include "TPolyLine3D.h"
29 
30 ClassImp(TPrimary);
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 ///
34 /// Primary vertex particle default constructor
35 ///
36 
37 TPrimary::TPrimary()
38 {
39  //do nothing
40  fPart = 0;
41  fFirstMother = 0;
42  fSecondMother = 0;
43  fGeneration = 0;
44  fPx = 0;
45  fPy = 0;
46  fPz = 0;
47  fEtot = 0;
48  fVx = 0;
49  fVy = 0;
50  fVz = 0;
51  fTime = 0;
52  fTimeEnd = 0;
53  fType = "";
54 
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 ///
59 /// TPrimary vertex particle normal constructor
60 ///
61 
62 TPrimary::TPrimary(Int_t part, Int_t first, Int_t second, Int_t gener,
63  Double_t px, Double_t py, Double_t pz,
64  Double_t etot, Double_t vx, Double_t vy, Double_t vz,
65  Double_t time, Double_t timend, const char *type)
66 {
67  fPart = part;
68  fFirstMother = first;
69  fSecondMother = second;
70  fGeneration = gener;
71  fPx = px;
72  fPy = py;
73  fPz = pz;
74  fEtot = etot;
75  fVx = vx;
76  fVy = vy;
77  fVz = vz;
78  fTime = time;
79  fTimeEnd = timend;
80  fType = type;
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 ///
85 /// Primaray vertex particle default destructor
86 ///
87 
88 TPrimary::~TPrimary()
89 {
90  //do nothing
91 }
92 
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Compute distance from point px,py to a primary track
96 ///
97 /// Compute the closest distance of approach from point px,py to each segment
98 /// of a track.
99 /// The distance is computed in pixels units.
100 ///
101 
102 Int_t TPrimary::DistancetoPrimitive(Int_t px, Int_t py)
103 {
104  const Int_t big = 9999;
105  Float_t xv[3], xe[3], xndc[3];
106  Float_t rmin[3], rmax[3];
107  TView *view = gPad->GetView();
108  if(!view) return big;
109 
110  // compute first and last point in pad coordinates
111  Float_t pmom = TMath::Sqrt(fPx*fPx+fPy*fPy+fPz*fPz);
112  if (pmom == 0) return big;
113  view->GetRange(rmin,rmax);
114  Float_t rbox = rmax[2];
115  xv[0] = fVx;
116  xv[1] = fVy;
117  xv[2] = fVz;
118  xe[0] = fVx+rbox*fPx/pmom;
119  xe[1] = fVy+rbox*fPy/pmom;
120  xe[2] = fVz+rbox*fPz/pmom;
121  view->WCtoNDC(xv, xndc);
122  Float_t x1 = xndc[0];
123  Float_t y1 = xndc[1];
124  view->WCtoNDC(xe, xndc);
125  Float_t x2 = xndc[0];
126  Float_t y2 = xndc[1];
127 
128  return DistancetoLine(px,py,x1,y1,x2,y2);
129 }
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Execute action corresponding to one event
134 ///
135 
136 void TPrimary::ExecuteEvent(Int_t, Int_t, Int_t)
137 {
138  gPad->SetCursor(kPointer);
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Return name of primary particle
143 
144 const char *TPrimary::GetName() const
145 {
146  static char def[4] = "XXX";
147  const TAttParticle *ap = GetParticle();
148  if (ap) return ap->GetName();
149  else return def;
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 ///
154 /// Returning a pointer to the particle attributes
155 ///
156 
157 const TAttParticle *TPrimary::GetParticle() const
158 {
159  if (!TAttParticle::fgList) TAttParticle::DefinePDG();
160  return TAttParticle::GetParticle(fPart);
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Return title of primary particle
165 
166 const char *TPrimary::GetTitle() const
167 {
168  static char title[128];
169  Float_t pmom = TMath::Sqrt(fPx*fPx+fPy*fPy+fPz*fPz);
170  snprintf(title,128,"pmom=%f GeV",pmom);
171  return title;
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 ///
176 /// Paint a primary track
177 ///
178 
179 void TPrimary::Paint(Option_t *option)
180 {
181  Float_t rmin[3], rmax[3];
182  static TPolyLine3D *pline = 0;
183  if (!pline) {
184  pline = new TPolyLine3D(2);
185  }
186  Float_t pmom = TMath::Sqrt(fPx*fPx+fPy*fPy+fPz*fPz);
187  if (pmom == 0) return;
188  TView *view = gPad->GetView();
189  if (!view) return;
190  view->GetRange(rmin,rmax);
191  Float_t rbox = rmax[2];
192  pline->SetPoint(0,fVx, fVy, fVz);
193  Float_t xend = fVx+rbox*fPx/pmom;
194  Float_t yend = fVy+rbox*fPy/pmom;
195  Float_t zend = fVz+rbox*fPz/pmom;
196  pline->SetPoint(1, xend, yend, zend);
197  pline->SetLineColor(GetLineColor());
198  pline->SetLineStyle(GetLineStyle());
199  pline->SetLineWidth(GetLineWidth());
200  pline->Paint(option);
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 ///
205 /// Print the internals of the primary vertex particle
206 ///
207 
208 void TPrimary::Print(Option_t *) const
209 {
210  char def[8] = "XXXXXXX";
211  const char *name;
212  TAttParticle *ap = (TAttParticle*)GetParticle();
213  if (ap) name = ap->GetName();
214  else name = def;
215  Printf("TPrimary: %-13s p: %8f %8f %8f Vertex: %8e %8e %8e %5d %5d %s",
216  name,fPx,fPy,fPz,fVx,fVy,fVz,
217  fFirstMother,fSecondMother,fType.Data());
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Return total X3D size of this primary
222 ///
223 
224 void TPrimary::Sizeof3D() const
225 {
226  Float_t pmom = TMath::Sqrt(fPx*fPx+fPy*fPy+fPz*fPz);
227  if (pmom == 0) return;
228  Int_t npoints = 2;
229  gSize3D.numPoints += npoints;
230  gSize3D.numSegs += (npoints-1);
231  gSize3D.numPolys += 0;
232 
233 }
234