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// -------------------------------------------------------------------------
34
35// ----- Standard constructor ------------------------------------------
36ShipMCTrack::ShipMCTrack(Int_t pdgCode, Int_t motherId, Double_t px,
37 Double_t py, Double_t pz, Double_t M, Double_t x,
38 Double_t y, Double_t z, Double_t t, Int_t nPoints,
39 Int_t eventID, Int_t trackID, Double_t w)
40 : TObject(),
41 fPdgCode(pdgCode),
42 fMotherId(motherId),
43 fPx(px),
44 fPy(py),
45 fPz(pz),
46 fM(M),
47 fStartX(x),
48 fStartY(y),
49 fStartZ(z),
50 fStartT(t),
51 fW(w),
52 fProcID(44),
53 fNPoints(nPoints),
54 fEventID(eventID),
55 fTrackID(trackID) {}
56// -------------------------------------------------------------------------
57
58// ----- Copy constructor ----------------------------------------------
60 : TObject(track),
61 fPdgCode(track.fPdgCode),
62 fMotherId(track.fMotherId),
63 fPx(track.fPx),
64 fPy(track.fPy),
65 fPz(track.fPz),
66 fM(track.fM),
67 fStartX(track.fStartX),
68 fStartY(track.fStartY),
69 fStartZ(track.fStartZ),
70 fStartT(track.fStartT),
71 fW(track.GetWeight()),
72 fProcID(track.GetProcID()),
73 fNPoints(track.fNPoints),
74 fEventID(track.fEventID),
75 fTrackID(track.fTrackID) {}
76// -------------------------------------------------------------------------
77
78// ----- Constructor from TParticle ------------------------------------
80 : TObject(),
81 fPdgCode(part->GetPdgCode()),
82 fMotherId(part->GetMother(0)),
83 fPx(part->Px()),
84 fPy(part->Py()),
85 fPz(part->Pz()),
86 fM([](const TParticle* p) {
87 Double_t m2 = p->Energy() * p->Energy() - p->P() * p->P();
88 if (m2 >= 0.) return TMath::Sqrt(m2);
89 // Tiny negative: numerical noise for on-shell massless particle
90 Double_t e2 = p->Energy() * p->Energy();
91 if (-m2 < 1e-10 * e2) return 0.;
92 // Genuinely spacelike (virtual photon): store negative mass (ROOT
93 // convention)
94 return -TMath::Sqrt(-m2);
95 }(part)),
96 fStartX(part->Vx()),
97 fStartY(part->Vy()),
98 fStartZ(part->Vz()),
99 fStartT(part->T() * 1e09),
100 fW(part->GetWeight()),
101 fProcID(part->GetUniqueID()),
102 fNPoints(0),
103 fEventID(0),
104 fTrackID(0) {}
105// -------------------------------------------------------------------------
106
107// ----- Destructor ----------------------------------------------------
109// -------------------------------------------------------------------------
110
111// ----- Public method Print -------------------------------------------
112void ShipMCTrack::Print(Int_t trackId) const {
113 LOG(debug) << "Track " << trackId << ", mother : " << fMotherId << ", Type "
114 << fPdgCode << ", momentum (" << fPx << ", " << fPy << ", " << fPz
115 << ") GeV";
116 /* LOG(DEBUG2) << " Ref " << GetNPoints(kREF)
117 << ", TutDet " << GetNPoints(kTutDet)
118 << ", Rutherford " << GetNPoints(kFairRutherford) ;
119 */
120}
121// -------------------------------------------------------------------------
122// ----- Public method GetEnergy -----------------------------------------
123
124Double_t ShipMCTrack::GetEnergy() const {
125 if (fM < 0) {
126 // older data, mass not made persistent
127 Double_t mass = GetMass();
128 return TMath::Sqrt(mass * mass + fPx * fPx + fPy * fPy + fPz * fPz);
129 } else {
130 return TMath::Sqrt(fM * fM + fPx * fPx + fPy * fPy + fPz * fPz);
131 }
132}
133// ----- Public method GetMass -----------------------------------------
134Double_t ShipMCTrack::GetMass() const {
135 if (fM < 0) {
136 // older data, mass not made persistent
137 if (TDatabasePDG::Instance()) {
138 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
139 if (particle) {
140 return particle->Mass();
141 } else {
142 return 0.;
143 }
144 }
145 }
146 return fM;
147}
148// -------------------------------------------------------------------------
149
150// ----- Public method GetWeight -------------------------------------
151Double_t ShipMCTrack::GetWeight() const { return fW; }
152// -------------------------------------------------------------------------
153
154// ----- Public method GetRapidity -------------------------------------
155Double_t ShipMCTrack::GetRapidity() const {
156 Double_t e = GetEnergy();
157 Double_t y = 0.5 * TMath::Log((e + fPz) / (e - fPz));
158 return y;
159}
160// -------------------------------------------------------------------------
161
162// ----- Public method GetNPoints --------------------------------------
164 /* // TODO: Where does this come from
165 if ( detId == kREF ) { return ( fNPoints & 1); }
166 else if ( detId == kTutDet ) { return ( (fNPoints & ( 7 << 1) ) >> 1); }
167 else if ( detId == kFairRutherford ) { return ( (fNPoints & (31 << 4) ) >>
168 4); } else { LOG(error) << "Unknown detector ID " << detId ; return 0;
169 }
170 */
171 return 0;
172}
173// -------------------------------------------------------------------------
174
175// ----- Public method SetNPoints --------------------------------------
176void ShipMCTrack::SetNPoints(Int_t iDet, Int_t nPoints) {
177 /*
178 if ( iDet == kREF ) {
179 if ( nPoints < 0 ) { nPoints = 0; }
180 else if ( nPoints > 1 ) { nPoints = 1; }
181 fNPoints = ( fNPoints & ( ~ 1 ) ) | nPoints;
182 }
183
184 else if ( iDet == kTutDet ) {
185 if ( nPoints < 0 ) { nPoints = 0; }
186 else if ( nPoints > 7 ) { nPoints = 7; }
187 fNPoints = ( fNPoints & ( ~ ( 7 << 1 ) ) ) | ( nPoints << 1 );
188 }
189
190 else if ( iDet == kFairRutherford ) {
191 if ( nPoints < 0 ) { nPoints = 0; }
192 else if ( nPoints > 31 ) { nPoints = 31; }
193 fNPoints = ( fNPoints & ( ~ ( 31 << 4 ) ) ) | ( nPoints << 4 );
194 }
195
196 else LOG(error) << "Unknown detector ID " << iDet ;
197 */
198}
199
200void ShipMCTrack::SetEventID(const Int_t& eventID) { fEventID = eventID; }
201
202void ShipMCTrack::SetTrackID(const Int_t& trackID) { fTrackID = trackID; }
203// -------------------------------------------------------------------------
const Int_t debug
DetectorId
Double_t GetWeight() const
void Print(Int_t iTrack=0) const
Double32_t fPy
Definition: ShipMCTrack.h:96
Int_t fEventID
Definition: ShipMCTrack.h:125
Int_t fPdgCode
Definition: ShipMCTrack.h:90
Double_t GetRapidity() const
Double_t GetMass() const
void SetTrackID(const Int_t &trackID)
Int_t fTrackID
Definition: ShipMCTrack.h:128
Double32_t fW
Definition: ShipMCTrack.h:102
Double32_t fM
Definition: ShipMCTrack.h:96
void SetEventID(const Int_t &eventID)
Double_t GetEnergy() const
Int_t GetNPoints(DetectorId detId) const
void SetNPoints(Int_t iDet, Int_t np)
Int_t fMotherId
Definition: ShipMCTrack.h:93
Double32_t fPz
Definition: ShipMCTrack.h:96
virtual ~ShipMCTrack()
Double32_t fPx
Definition: ShipMCTrack.h:96