FairShip
Loading...
Searching...
No Matches
ShipMCTrack.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5// -------------------------------------------------------------------------
6// ----- ShipMCTrack source file -----
7// -------------------------------------------------------------------------
8#include "ShipMCTrack.h"
9
10#include "FairLogger.h" // for FairLogger, etc
11#include "TDatabasePDG.h" // for TDatabasePDG
12#include "TParticle.h" // for TParticle
13#include "TParticlePDG.h" // for TParticlePDG
14
15// ----- Default constructor -------------------------------------------
17 : TObject(),
18 fPdgCode(0),
19 fMotherId(-1),
20 fPx(0.),
21 fPy(0.),
22 fPz(0.),
23 fM(-1.),
24 fStartX(0.),
25 fStartY(0.),
26 fStartZ(0.),
27 fStartT(0.),
28 fW(1.),
29 fProcID(44),
30 fNPoints(0),
31 fEventID(0),
32 fTrackID(0),
33 fSplitSet(-1),
35 fSplitWeight(0.) {}
36// -------------------------------------------------------------------------
37
38// ----- Standard constructor ------------------------------------------
39ShipMCTrack::ShipMCTrack(Int_t pdgCode, Int_t motherId, Double_t px,
40 Double_t py, Double_t pz, Double_t M, Double_t x,
41 Double_t y, Double_t z, Double_t t, Int_t nPoints,
42 Int_t eventID, Int_t trackID, Double_t w)
43 : TObject(),
44 fPdgCode(pdgCode),
45 fMotherId(motherId),
46 fPx(px),
47 fPy(py),
48 fPz(pz),
49 fM(M),
50 fStartX(x),
51 fStartY(y),
52 fStartZ(z),
53 fStartT(t),
54 fW(w),
55 fProcID(44),
56 fNPoints(nPoints),
57 fEventID(eventID),
58 fTrackID(trackID),
59 fSplitSet(-1),
61 fSplitWeight(0.) {}
62// -------------------------------------------------------------------------
63
64// ----- Copy constructor ----------------------------------------------
66 : TObject(track),
67 fPdgCode(track.fPdgCode),
68 fMotherId(track.fMotherId),
69 fPx(track.fPx),
70 fPy(track.fPy),
71 fPz(track.fPz),
72 fM(track.fM),
73 fStartX(track.fStartX),
74 fStartY(track.fStartY),
75 fStartZ(track.fStartZ),
76 fStartT(track.fStartT),
77 fW(track.GetWeight()),
78 fProcID(track.GetProcID()),
79 fNPoints(track.fNPoints),
80 fEventID(track.fEventID),
81 fTrackID(track.fTrackID),
82 fSplitSet(track.fSplitSet),
85// -------------------------------------------------------------------------
86
87// ----- Constructor from TParticle ------------------------------------
89 : TObject(),
90 fPdgCode(part->GetPdgCode()),
91 fMotherId(part->GetMother(0)),
92 fPx(part->Px()),
93 fPy(part->Py()),
94 fPz(part->Pz()),
95 fM([](const TParticle* p) {
96 Double_t m2 = p->Energy() * p->Energy() - p->P() * p->P();
97 if (m2 >= 0.) return TMath::Sqrt(m2);
98 // Tiny negative: numerical noise for on-shell massless particle
99 Double_t e2 = p->Energy() * p->Energy();
100 if (-m2 < 1e-10 * e2) return 0.;
101 // Genuinely spacelike (virtual photon): store negative mass (ROOT
102 // convention)
103 return -TMath::Sqrt(-m2);
104 }(part)),
105 fStartX(part->Vx()),
106 fStartY(part->Vy()),
107 fStartZ(part->Vz()),
108 fStartT(part->T() * 1e09),
109 fW(part->GetWeight()),
110 fProcID(part->GetUniqueID()),
111 fNPoints(0),
112 fEventID(0),
113 fTrackID(0),
114 fSplitSet(-1),
115 fSplitRole(kNotSplit),
116 fSplitWeight(0.) {}
117// -------------------------------------------------------------------------
118
119// ----- Destructor ----------------------------------------------------
120ShipMCTrack::~ShipMCTrack() = default;
121// -------------------------------------------------------------------------
122
123// ----- Public method Print -------------------------------------------
124void ShipMCTrack::Print(Int_t trackId) const {
125 LOG(debug) << "Track " << trackId << ", mother : " << fMotherId << ", Type "
126 << fPdgCode << ", momentum (" << fPx << ", " << fPy << ", " << fPz
127 << ") GeV";
128}
129// -------------------------------------------------------------------------
130// ----- Public method GetEnergy -----------------------------------------
131
132Double_t ShipMCTrack::GetEnergy() const {
133 if (fM < 0) {
134 // older data, mass not made persistent
135 Double_t mass = GetMass();
136 return TMath::Sqrt(mass * mass + fPx * fPx + fPy * fPy + fPz * fPz);
137 } else {
138 return TMath::Sqrt(fM * fM + fPx * fPx + fPy * fPy + fPz * fPz);
139 }
140}
141// ----- Public method GetMass -----------------------------------------
142Double_t ShipMCTrack::GetMass() const {
143 if (fM < 0) {
144 // older data, mass not made persistent
145 if (TDatabasePDG::Instance()) {
146 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
147 if (particle) {
148 return particle->Mass();
149 } else {
150 return 0.;
151 }
152 }
153 }
154 return fM;
155}
156// -------------------------------------------------------------------------
157
158// ----- Public method GetWeight -------------------------------------
159Double_t ShipMCTrack::GetWeight() const { return fW; }
160// -------------------------------------------------------------------------
161
162// ----- Public method GetRapidity -------------------------------------
163Double_t ShipMCTrack::GetRapidity() const {
164 Double_t e = GetEnergy();
165 Double_t y = 0.5 * TMath::Log((e + fPz) / (e - fPz));
166 return y;
167}
168// -------------------------------------------------------------------------
169
170void ShipMCTrack::SetEventID(const Int_t& eventID) { fEventID = eventID; }
171
172void ShipMCTrack::SetTrackID(const Int_t& trackID) { fTrackID = trackID; }
173// -------------------------------------------------------------------------
LANGUAGES CXX if(FAIRSHIP_VERSION_TWEAK) set(PROJECT_VERSION_TWEAK $
const Int_t debug
Double_t GetWeight() const
~ShipMCTrack() override
void Print(Int_t iTrack=0) const
Double32_t fPy
Double_t GetRapidity() const
Double_t GetMass() const
void SetTrackID(const Int_t &trackID)
Double32_t fStartX
Int_t GetProcID() const
Definition ShipMCTrack.h:71
Double32_t fW
Double32_t fStartZ
Double32_t fM
Double32_t fStartY
void SetEventID(const Int_t &eventID)
Double32_t fSplitWeight
Double32_t fStartT
Int_t fSplitSet
Double_t GetEnergy() const
Int_t GetPdgCode() const
Definition ShipMCTrack.h:60
Int_t fSplitRole
Int_t fMotherId
Double32_t fPz
Double32_t fPx
@ kNotSplit
not part of a split set
Definition ShipMCTrack.h:32