Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TParticle.cxx
Go to the documentation of this file.
1// @(#)root/eg:$Id$
2// Author: Rene Brun , Federico Carminati 26/04/99
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 TParticle
13 \ingroup eg
14
15Description of the dynamic properties of a particle.
16
17A dynamic particle class created by event generators and used during
18the propagation in detectors. The static attributes of a TParticle
19are described by TParticlePDG.
20
21\verbatim
22 Int_t fPdgCode; // PDG code of the particle
23 Int_t fStatusCode; // generation status code
24 Int_t fMother[2]; // Indices of the mother particles
25 Int_t fDaughter[2]; // Indices of the daughter particles
26 Float_t fWeight; // particle weight
27
28 Double_t fCalcMass; // Calculated mass
29
30 Double_t fPx; // x component of momentum
31 Double_t fPy; // y component of momentum
32 Double_t fPz; // z component of momentum
33 Double_t fE; // Energy
34
35 Double_t fVx; // x of production vertex
36 Double_t fVy; // y of production vertex
37 Double_t fVz; // z of production vertex
38 Double_t fVt; // t of production vertex
39
40 Double_t fPolarTheta; // Polar angle of polarisation
41 Double_t fPolarPhi; // azymutal angle of polarisation
42
43 TParticlePDG* fParticlePDG; //! reference to the particle record in PDG database
44\endverbatim
45*/
46
47#include "TParticle.h"
48
49#include "TBuffer.h"
50#include "TView.h"
51#include "TVirtualPad.h"
52#include "TPolyLine3D.h"
53#include "TParticlePDG.h"
54#include "TDatabasePDG.h"
55#include "TClass.h"
56#include "X3DBuffer.h"
57
58
59////////////////////////////////////////////////////////////////////////////////
60///default constructor
61
63 fPdgCode(0), fStatusCode(0), fWeight(0),fCalcMass(0), fPx(0), fPy(0),
64 fPz(0), fE(0), fVx(0), fVy(0), fVz(0), fVt(0), fPolarTheta(0), fPolarPhi(0)
65{
66 fMother[0] = 0;
67 fMother[1] = 0;
68 fDaughter[0] = 0;
69 fDaughter[1] = 0;
70 fParticlePDG = 0;
71}
72
73////////////////////////////////////////////////////////////////////////////////
74///constructor
75
81 fPdgCode(pdg), fStatusCode(status), fWeight(1.),fPx(px), fPy(py),
82 fPz(pz), fE(etot), fVx(vx), fVy(vy), fVz(vz), fVt(time)
83{
84 fMother[0] = mother1;
85 fMother[1] = mother2;
88
89 SetPolarisation(0,0,0);
90
92}
93
94////////////////////////////////////////////////////////////////////////////////
95///constructor
96
100 const TLorentzVector &p,
101 const TLorentzVector &v) :
102 fPdgCode(pdg), fStatusCode(status), fWeight(1.),fPx(p.Px()), fPy(p.Py()),
103 fPz(p.Pz()), fE(p.E()), fVx(v.X()), fVy(v.Y()), fVz(v.Z()), fVt(v.T())
104{
105 fMother[0] = mother1;
106 fMother[1] = mother2;
107 fDaughter[0] = daughter1;
108 fDaughter[1] = daughter2;
109
110 SetPolarisation(0,0,0);
111
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// copy constructor
117
119 TObject(p), TAttLine(p), TAtt3D(p), fPdgCode(p.fPdgCode), fStatusCode(p.fStatusCode),
120 fWeight(p.fWeight), fCalcMass(p.fCalcMass), fPx(p.fPx), fPy(p.fPy), fPz(p.fPz),
121 fE(p.fE), fVx(p.fVx), fVy(p.fVy), fVz(p.fVz), fVt(p.fVt), fPolarTheta(p.fPolarTheta),
122 fPolarPhi(p.fPolarPhi), fParticlePDG(p.fParticlePDG)
123{
124 fMother[0]=p.fMother[0];
125 fMother[1]=p.fMother[1];
126 fDaughter[0]=p.fDaughter[0];
127 fDaughter[1]=p.fDaughter[1];
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Equal operator
132
134{
135 if(this!=&p) {
137 TAttLine::operator=(p);
138 TAtt3D::operator=(p);
139 fPdgCode=p.fPdgCode;
140 fStatusCode=p.fStatusCode;
141 fMother[0]=p.fMother[0];
142 fMother[1]=p.fMother[1];
143 fDaughter[0]=p.fDaughter[0];
144 fDaughter[1]=p.fDaughter[1];
145 fWeight=p.fWeight;
146
147 fCalcMass=p.fCalcMass;
148
149 fPx=p.fPx;
150 fPy=p.fPy;
151 fPz=p.fPz;
152 fE=p.fE;
153
154 fVx=p.fVx;
155 fVy=p.fVy;
156 fVz=p.fVz;
157 fVt=p.fVt;
158
159 fPolarTheta=p.fPolarTheta;
160 fPolarPhi=p.fPolarPhi;
161
162 fParticlePDG=p.fParticlePDG;
163 }
164 return *this;
165}
166
167////////////////////////////////////////////////////////////////////////////////
168///destructor
169
173
174////////////////////////////////////////////////////////////////////////////////
175/// Return nominal particle mass from PDG table.
176
178{
179 return GetPDG()->Mass();
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Return beauty quantum number.
184
186{
187 return GetPDG()->Beauty();
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Return charm quantum number.
192
194{
195 return GetPDG()->Charm();
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Return strangeness quantum number.
200
202{
203 return GetPDG()->Strangeness();
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Compute distance from point px,py to a primary track
208///
209/// Compute the closest distance of approach from point px,py to each segment
210/// of a track.
211/// The distance is computed in pixels units.
212///ß
213
215{
216 const Int_t big = 9999;
217 Float_t xv[3], xe[3], xndc[3];
218 Float_t rmin[3], rmax[3];
219 TView *view = gPad->GetView();
220 if(!view) return big;
221
222 // compute first and last point in pad coordinates
223 Float_t pmom = this->P();
224 if (pmom == 0) return big;
225 view->GetRange(rmin,rmax);
226 Float_t rbox = rmax[2];
227 xv[0] = fVx;
228 xv[1] = fVy;
229 xv[2] = fVz;
230 xe[0] = xv[0]+rbox*fPx/pmom;
231 xe[1] = xv[1]+rbox*fPy/pmom;
232 xe[2] = xv[2]+rbox*fPz/pmom;
233 view->WCtoNDC(xv, xndc);
234 Float_t x1 = xndc[0];
235 Float_t y1 = xndc[1];
236 view->WCtoNDC(xe, xndc);
237 Float_t x2 = xndc[0];
238 Float_t y2 = xndc[1];
239
240 return DistancetoLine(px,py,x1,y1,x2,y2);
241}
242
243
244////////////////////////////////////////////////////////////////////////////////
245/// Execute action corresponding to one event
246///
247
249{
250 gPad->SetCursor(kPointer);
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Return particle name
255
256const char* TParticle::GetName() const {
257 static char def[4] = "XXX";
258 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPdgCode);
259 if (ap) return ap->GetName();
260 else return def;
261}
262
263
264////////////////////////////////////////////////////////////////////////////////
265/// Returns a pointer to the TParticlePDG object using the pdgcode.
266/// - if mode == 0 (default) always get a fresh value for the pointer.
267/// - if mode != 0 this function returns directly the previously
268/// computed pointer from a previous call
269/// One can use mode=1 (faster) when the TParticle object is not part of a
270/// TClonesArray used in split mode in a Root TTree.
271
273{
274 if (!mode || !fParticlePDG) {
276 }
277 return fParticlePDG;
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Return particle polarisation
282
284{
285 if(fPolarTheta == -99 && fPolarPhi == -99)
286 //No polarisation to return
287 v.SetXYZ(0.,0.,0.);
288 else
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Return particle title
296
297const char *TParticle::GetTitle() const
298{
299 static char def[4] = "XXX";
300 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPdgCode);
301 if (ap) return ap->GetTitle();
302 else return def;
303}
304
305////////////////////////////////////////////////////////////////////////////////
306///
307/// Paint a primary track
308///
309
311{
312 Float_t rmin[3], rmax[3];
313 static TPolyLine3D *pline = 0;
314 if (!pline) {
315 pline = new TPolyLine3D(2);
316 }
317 Float_t pmom = this->P();
318 if (pmom == 0) return;
319 TView *view = gPad->GetView();
320 if (!view) return;
321 view->GetRange(rmin,rmax);
322 Float_t rbox = rmax[2];
323 pline->SetPoint(0,Vx(), Vy(), Vz());
324 Float_t xend = Vx()+rbox*Px()/pmom;
325 Float_t yend = Vy()+rbox*Py()/pmom;
326 Float_t zend = Vz()+rbox*Pz()/pmom;
327 pline->SetPoint(1, xend, yend, zend);
332}
333
334////////////////////////////////////////////////////////////////////////////////
335///
336/// Print the internals of the primary vertex particle
337///
338
340{
341 Printf("TParticle: %-13s p: %8f %8f %8f Vertex: %8e %8e %8e %5d %5d",
342 GetName(),Px(),Py(),Pz(),Vx(),Vy(),Vz(),
343 fMother[0],fMother[1]);
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Change the PDG code for this particle
348///
349/// Get a new pointer to a TParticlePDG from TDatabasePDG.
350/// Recompute the mass.
351
353{
354 static Int_t nWarnings = 0;
355 fPdgCode = pdg;
356 fParticlePDG = TDatabasePDG::Instance()->GetParticle(pdg);
357 if (fParticlePDG) {
359 } else {
360 if (nWarnings < 10) {
361 Warning("SetPdgCode","PDG code %d unknown from TDatabasePDG",pdg);
362 nWarnings++;
363 }
365 if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
366 else fCalcMass = -TMath::Sqrt(-a2);
367 }
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Set particle polarisation
372
383
384////////////////////////////////////////////////////////////////////////////////
385/// Return total X3D size of this primary
386///
387
389{
390 Float_t pmom = this->P();
391 if (pmom == 0) return;
392 Int_t npoints = 2;
393 gSize3D.numPoints += npoints;
394 gSize3D.numSegs += (npoints-1);
395 gSize3D.numPolys += 0;
396
397}
398
399////////////////////////////////////////////////////////////////////////////////
400/// Stream an object of class TParticle.
401
403{
404 if (R__b.IsReading()) {
406 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
407 if (R__v > 1) {
408 R__b.ReadClassBuffer(TParticle::Class(), this, R__v, R__s, R__c);
410 return;
411 }
412 //====process old versions before automatic schema evolution
415 R__b >> fPdgCode;
416 R__b >> fStatusCode;
417 R__b.ReadStaticArray(fMother);
418 R__b.ReadStaticArray(fDaughter);
419 R__b >> fWeight;
420 R__b >> fCalcMass;
421 R__b >> fPx;
422 R__b >> fPy;
423 R__b >> fPz;
424 R__b >> fE;
425 R__b >> fVx;
426 R__b >> fVy;
427 R__b >> fVz;
428 R__b >> fVt;
429 R__b >> fPolarTheta;
430 R__b >> fPolarPhi;
432 R__b.CheckByteCount(R__s, R__c, TParticle::IsA());
433 //====end of old versions
434
435 } else {
436 R__b.WriteClassBuffer(TParticle::Class(),this);
437 }
438}
@ kPointer
Definition GuiTypes.h:375
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define X(type, name)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2509
#define gPad
#define gSize3D
Definition X3DBuffer.h:40
Use this attribute class when an object should have 3D capabilities.
Definition TAtt3D.h:19
Line Attributes class.
Definition TAttLine.h:20
virtual void Streamer(TBuffer &)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:44
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:36
Int_t DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
Compute distance from point px,py to a line.
Definition TAttLine.cxx:210
Buffer base class used for serializing objects.
Definition TBuffer.h:43
static TDatabasePDG * Instance()
static function
Mother of all ROOT objects.
Definition TObject.h:41
TObject & operator=(const TObject &rhs) noexcept
TObject assignment operator.
Definition TObject.h:299
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:972
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
Description of the static properties of a particle.
Int_t Strangeness() const
Int_t Beauty() const
Double_t Mass() const
Int_t Charm() const
Description of the dynamic properties of a particle.
Definition TParticle.h:26
Int_t fDaughter[2]
Definition TParticle.h:34
Double_t GetMass() const
Return nominal particle mass from PDG table.
Double_t fVy
Definition TParticle.h:45
Double_t fPx
Definition TParticle.h:39
Double_t Px() const
Definition TParticle.h:131
TParticlePDG * fParticlePDG
Definition TParticle.h:52
const char * GetTitle() const override
Return particle title.
Double_t Py() const
Definition TParticle.h:132
static TClass * Class()
Double_t fPolarTheta
Definition TParticle.h:49
void GetPolarisation(TVector3 &v) const
Return particle polarisation.
TParticle & operator=(const TParticle &)
Equal operator.
~TParticle() override
destructor
void SetPolarisation(Double_t theta, Double_t phi)
Definition TParticle.h:111
void Paint(Option_t *option="") override
Paint a primary track.
Float_t fWeight
Definition TParticle.h:35
Int_t Beauty() const
Return beauty quantum number.
TParticlePDG * GetPDG(Int_t mode=0) const
Returns a pointer to the TParticlePDG object using the pdgcode.
Double_t P() const
Definition TParticle.h:134
Double_t fVz
Definition TParticle.h:46
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a primary track.
Int_t Charm() const
Return charm quantum number.
Double_t fCalcMass
Definition TParticle.h:37
const char * GetName() const override
Return particle name.
Double_t Pz() const
Definition TParticle.h:133
TClass * IsA() const override
Definition TParticle.h:182
Double_t Vy() const
Definition TParticle.h:126
Int_t fPdgCode
Definition TParticle.h:31
Double_t fE
Definition TParticle.h:42
Double_t fVt
Definition TParticle.h:47
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Double_t fPz
Definition TParticle.h:41
TParticle()
reference to the particle record in PDG database
Definition TParticle.cxx:62
void SetPdgCode(Int_t pdg)
Change the PDG code for this particle.
Double_t Vx() const
Definition TParticle.h:125
Double_t fVx
Definition TParticle.h:44
Double_t fPy
Definition TParticle.h:40
void Sizeof3D() const override
Return total X3D size of this primary.
Int_t fStatusCode
Definition TParticle.h:32
Double_t fPolarPhi
Definition TParticle.h:50
void Streamer(TBuffer &) override
Stream an object of class TParticle.
Int_t Strangeness() const
Return strangeness quantum number.
Int_t fMother[2]
Definition TParticle.h:33
Double_t Vz() const
Definition TParticle.h:127
void Print(Option_t *option="") const override
Print the internals of the primary vertex particle.
A 3-dimensional polyline.
Definition TPolyLine3D.h:33
virtual void SetPoint(Int_t point, Double_t x, Double_t y)
Set point number n to (x, y) If n is greater than the current size, the arrays are automatically exte...
void Paint(Option_t *option="") override
Paint this polyline with its current attributes.
See TView3D.
Definition TView.h:25
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
virtual void GetRange(Float_t *min, Float_t *max)=0
Double_t ACos(Double_t)
Returns the principal value of the arc cosine of x, expressed in radians.
Definition TMath.h:643
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Definition TMath.h:657
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:605
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:599
Definition rbox.py:1
TPolyLine * pline
Definition polyline.C:4