forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TParticle.cxx
439 lines (367 loc) · 12.8 KB
/
TParticle.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
// @(#)root/eg:$Id$
// Author: Rene Brun , Federico Carminati 26/04/99
/*************************************************************************
* 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. *
*************************************************************************/
/** \class TParticle
\ingroup eg
Description of the dynamic properties of a particle.
A dynamic particle class created by event generators and used during
the propagation in detectors. The static attributes of a TParticle
are described by TParticlePDG.
\verbatim
Int_t fPdgCode; // PDG code of the particle
Int_t fStatusCode; // generation status code
Int_t fMother[2]; // Indices of the mother particles
Int_t fDaughter[2]; // Indices of the daughter particles
Float_t fWeight; // particle weight
Double_t fCalcMass; // Calculated mass
Double_t fPx; // x component of momentum
Double_t fPy; // y component of momentum
Double_t fPz; // z component of momentum
Double_t fE; // Energy
Double_t fVx; // x of production vertex
Double_t fVy; // y of production vertex
Double_t fVz; // z of production vertex
Double_t fVt; // t of production vertex
Double_t fPolarTheta; // Polar angle of polarisation
Double_t fPolarPhi; // azymutal angle of polarisation
TParticlePDG* fParticlePDG; //! reference to the particle record in PDG database
\endverbatim
*/
#include "TParticle.h"
#include "TBuffer.h"
#include "TView.h"
#include "TVirtualPad.h"
#include "TPolyLine3D.h"
#include "TParticlePDG.h"
#include "TDatabasePDG.h"
#include "TClass.h"
#include "X3DBuffer.h"
ClassImp(TParticle)
////////////////////////////////////////////////////////////////////////////////
///default constructor
TParticle::TParticle() :
fPdgCode(0), fStatusCode(0), fWeight(0),fCalcMass(0), fPx(0), fPy(0),
fPz(0), fE(0), fVx(0), fVy(0), fVz(0), fVt(0), fPolarTheta(0), fPolarPhi(0)
{
fMother[0] = 0;
fMother[1] = 0;
fDaughter[0] = 0;
fDaughter[1] = 0;
fParticlePDG = 0;
}
////////////////////////////////////////////////////////////////////////////////
///constructor
TParticle::TParticle(Int_t pdg, Int_t status,
Int_t mother1, Int_t mother2,
Int_t daughter1, Int_t daughter2,
Double_t px, Double_t py, Double_t pz, Double_t etot,
Double_t vx, Double_t vy, Double_t vz, Double_t time):
fPdgCode(pdg), fStatusCode(status), fWeight(1.),fPx(px), fPy(py),
fPz(pz), fE(etot), fVx(vx), fVy(vy), fVz(vz), fVt(time)
{
fMother[0] = mother1;
fMother[1] = mother2;
fDaughter[0] = daughter1;
fDaughter[1] = daughter2;
SetPolarisation(0,0,0);
SetPdgCode(pdg);
}
////////////////////////////////////////////////////////////////////////////////
///constructor
TParticle::TParticle(Int_t pdg, Int_t status,
Int_t mother1, Int_t mother2,
Int_t daughter1, Int_t daughter2,
const TLorentzVector &p,
const TLorentzVector &v) :
fPdgCode(pdg), fStatusCode(status), fWeight(1.),fPx(p.Px()), fPy(p.Py()),
fPz(p.Pz()), fE(p.E()), fVx(v.X()), fVy(v.Y()), fVz(v.Z()), fVt(v.T())
{
fMother[0] = mother1;
fMother[1] = mother2;
fDaughter[0] = daughter1;
fDaughter[1] = daughter2;
SetPolarisation(0,0,0);
SetPdgCode(pdg);
}
////////////////////////////////////////////////////////////////////////////////
/// copy constructor
TParticle::TParticle(const TParticle &p) :
TObject(p), TAttLine(p), TAtt3D(p), fPdgCode(p.fPdgCode), fStatusCode(p.fStatusCode),
fWeight(p.fWeight), fCalcMass(p.fCalcMass), fPx(p.fPx), fPy(p.fPy), fPz(p.fPz),
fE(p.fE), fVx(p.fVx), fVy(p.fVy), fVz(p.fVz), fVt(p.fVt), fPolarTheta(p.fPolarTheta),
fPolarPhi(p.fPolarPhi), fParticlePDG(p.fParticlePDG)
{
fMother[0]=p.fMother[0];
fMother[1]=p.fMother[1];
fDaughter[0]=p.fDaughter[0];
fDaughter[1]=p.fDaughter[1];
}
////////////////////////////////////////////////////////////////////////////////
/// Equal operator
TParticle& TParticle::operator=(const TParticle &p)
{
if(this!=&p) {
TObject::operator=(p);
TAttLine::operator=(p);
TAtt3D::operator=(p);
fPdgCode=p.fPdgCode;
fStatusCode=p.fStatusCode;
fMother[0]=p.fMother[0];
fMother[1]=p.fMother[1];
fDaughter[0]=p.fDaughter[0];
fDaughter[1]=p.fDaughter[1];
fWeight=p.fWeight;
fCalcMass=p.fCalcMass;
fPx=p.fPx;
fPy=p.fPy;
fPz=p.fPz;
fE=p.fE;
fVx=p.fVx;
fVy=p.fVy;
fVz=p.fVz;
fVt=p.fVt;
fPolarTheta=p.fPolarTheta;
fPolarPhi=p.fPolarPhi;
fParticlePDG=p.fParticlePDG;
}
return *this;
}
////////////////////////////////////////////////////////////////////////////////
///destructor
TParticle::~TParticle()
{
}
////////////////////////////////////////////////////////////////////////////////
/// Return nominal particle mass from PDG table.
Double_t TParticle::GetMass() const
{
return GetPDG()->Mass();
}
////////////////////////////////////////////////////////////////////////////////
/// Return beauty quantum number.
Int_t TParticle::Beauty() const
{
return GetPDG()->Beauty();
}
////////////////////////////////////////////////////////////////////////////////
/// Return charm quantum number.
Int_t TParticle::Charm() const
{
return GetPDG()->Charm();
}
////////////////////////////////////////////////////////////////////////////////
/// Return strangeness quantum number.
Int_t TParticle::Strangeness() const
{
return GetPDG()->Strangeness();
}
////////////////////////////////////////////////////////////////////////////////
/// Compute distance from point px,py to a primary track
///
/// Compute the closest distance of approach from point px,py to each segment
/// of a track.
/// The distance is computed in pixels units.
///ß
Int_t TParticle::DistancetoPrimitive(Int_t px, Int_t py)
{
const Int_t big = 9999;
Float_t xv[3], xe[3], xndc[3];
Float_t rmin[3], rmax[3];
TView *view = gPad->GetView();
if(!view) return big;
// compute first and last point in pad coordinates
Float_t pmom = this->P();
if (pmom == 0) return big;
view->GetRange(rmin,rmax);
Float_t rbox = rmax[2];
xv[0] = fVx;
xv[1] = fVy;
xv[2] = fVz;
xe[0] = xv[0]+rbox*fPx/pmom;
xe[1] = xv[1]+rbox*fPy/pmom;
xe[2] = xv[2]+rbox*fPz/pmom;
view->WCtoNDC(xv, xndc);
Float_t x1 = xndc[0];
Float_t y1 = xndc[1];
view->WCtoNDC(xe, xndc);
Float_t x2 = xndc[0];
Float_t y2 = xndc[1];
return DistancetoLine(px,py,x1,y1,x2,y2);
}
////////////////////////////////////////////////////////////////////////////////
/// Execute action corresponding to one event
///
void TParticle::ExecuteEvent(Int_t, Int_t, Int_t)
{
gPad->SetCursor(kPointer);
}
////////////////////////////////////////////////////////////////////////////////
/// Return particle name
const char* TParticle::GetName() const {
static char def[4] = "XXX";
const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPdgCode);
if (ap) return ap->GetName();
else return def;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns a pointer to the TParticlePDG object using the pdgcode.
/// - if mode == 0 (default) always get a fresh value for the pointer.
/// - if mode != 0 this function returns directly the previously
/// computed pointer from a previous call
/// One can use mode=1 (faster) when the TParticle object is not part of a
/// TClonesArray used in split mode in a Root TTree.
TParticlePDG* TParticle::GetPDG(Int_t mode) const
{
if (!mode || !fParticlePDG) {
fParticlePDG = TDatabasePDG::Instance()->GetParticle(fPdgCode);
}
return fParticlePDG;
}
////////////////////////////////////////////////////////////////////////////////
/// Return particle polarisation
void TParticle::GetPolarisation(TVector3 &v) const
{
if(fPolarTheta == -99 && fPolarPhi == -99)
//No polarisation to return
v.SetXYZ(0.,0.,0.);
else
v.SetXYZ(TMath::Cos(fPolarPhi)*TMath::Sin(fPolarTheta),
TMath::Sin(fPolarPhi)*TMath::Sin(fPolarTheta),
TMath::Cos(fPolarTheta));
}
////////////////////////////////////////////////////////////////////////////////
/// Return particle title
const char *TParticle::GetTitle() const
{
static char def[4] = "XXX";
const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPdgCode);
if (ap) return ap->GetTitle();
else return def;
}
////////////////////////////////////////////////////////////////////////////////
///
/// Paint a primary track
///
void TParticle::Paint(Option_t *option)
{
Float_t rmin[3], rmax[3];
static TPolyLine3D *pline = 0;
if (!pline) {
pline = new TPolyLine3D(2);
}
Float_t pmom = this->P();
if (pmom == 0) return;
TView *view = gPad->GetView();
if (!view) return;
view->GetRange(rmin,rmax);
Float_t rbox = rmax[2];
pline->SetPoint(0,Vx(), Vy(), Vz());
Float_t xend = Vx()+rbox*Px()/pmom;
Float_t yend = Vy()+rbox*Py()/pmom;
Float_t zend = Vz()+rbox*Pz()/pmom;
pline->SetPoint(1, xend, yend, zend);
pline->SetLineColor(GetLineColor());
pline->SetLineStyle(GetLineStyle());
pline->SetLineWidth(GetLineWidth());
pline->Paint(option);
}
////////////////////////////////////////////////////////////////////////////////
///
/// Print the internals of the primary vertex particle
///
void TParticle::Print(Option_t *) const
{
Printf("TParticle: %-13s p: %8f %8f %8f Vertex: %8e %8e %8e %5d %5d",
GetName(),Px(),Py(),Pz(),Vx(),Vy(),Vz(),
fMother[0],fMother[1]);
}
////////////////////////////////////////////////////////////////////////////////
/// Change the PDG code for this particle
///
/// Get a new pointer to a TParticlePDG from TDatabasePDG.
/// Recompute the mass.
void TParticle::SetPdgCode(Int_t pdg)
{
static Int_t nWarnings = 0;
fPdgCode = pdg;
fParticlePDG = TDatabasePDG::Instance()->GetParticle(pdg);
if (fParticlePDG) {
fCalcMass = fParticlePDG->Mass();
} else {
if (nWarnings < 10) {
Warning("SetPdgCode","PDG code %d unknown from TDatabasePDG",pdg);
nWarnings++;
}
Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
else fCalcMass = -TMath::Sqrt(-a2);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set particle polarisation
void TParticle::SetPolarisation(Double_t polx, Double_t poly, Double_t polz)
{
if(polx || poly || polz) {
fPolarTheta = TMath::ACos(polz/TMath::Sqrt(polx*polx+poly*poly+polz*polz));
fPolarPhi = TMath::Pi()+TMath::ATan2(-poly,-polx);
} else {
fPolarTheta = -99;
fPolarPhi = -99;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Return total X3D size of this primary
///
void TParticle::Sizeof3D() const
{
Float_t pmom = this->P();
if (pmom == 0) return;
Int_t npoints = 2;
gSize3D.numPoints += npoints;
gSize3D.numSegs += (npoints-1);
gSize3D.numPolys += 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Stream an object of class TParticle.
void TParticle::Streamer(TBuffer &R__b)
{
if (R__b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v > 1) {
R__b.ReadClassBuffer(TParticle::Class(), this, R__v, R__s, R__c);
fParticlePDG = TDatabasePDG::Instance()->GetParticle(fPdgCode);
return;
}
//====process old versions before automatic schema evolution
TObject::Streamer(R__b);
TAttLine::Streamer(R__b);
R__b >> fPdgCode;
R__b >> fStatusCode;
R__b.ReadStaticArray(fMother);
R__b.ReadStaticArray(fDaughter);
R__b >> fWeight;
R__b >> fCalcMass;
R__b >> fPx;
R__b >> fPy;
R__b >> fPz;
R__b >> fE;
R__b >> fVx;
R__b >> fVy;
R__b >> fVz;
R__b >> fVt;
R__b >> fPolarTheta;
R__b >> fPolarPhi;
fParticlePDG = TDatabasePDG::Instance()->GetParticle(fPdgCode);
R__b.CheckByteCount(R__s, R__c, TParticle::IsA());
//====end of old versions
} else {
R__b.WriteClassBuffer(TParticle::Class(),this);
}
}