CbmRoot
Loading...
Searching...
No Matches
CbmMCTrack.cxx
Go to the documentation of this file.
1/* Copyright (C) 2004-2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Florian Uhlig, Denis Bertini [committer] */
4
5// -------------------------------------------------------------------------
6// ----- CbmMCTrack source file -----
7// ----- Created 03/08/04 by V. Friese -----
8// -------------------------------------------------------------------------
9#include "CbmMCTrack.h"
10
11#include <Logger.h> // for LOG, Logger
12
13#include <TDatabasePDG.h> // for TDatabasePDG
14#include <TMCProcess.h> // for kPNoProcess, TMCProcessName
15#include <TObject.h> // for TObject
16#include <TParticle.h> // for TParticle
17#include <TParticlePDG.h> // for TParticlePDG
18
19#include <sstream> // for operator<<, basic_ostream, endl, stri...
20#include <string> // for char_traits
21
22using std::stringstream;
23
24
25// ----- Default constructor -------------------------------------------
27 : TObject()
28 , fProcessId(kPNoProcess)
29 , fPdgCode(0)
30 , fMotherId(-1)
31 , fPx(0.)
32 , fPy(0.)
33 , fPz(0.)
34 , fE(-1.)
35 , fStartX(0.)
36 , fStartY(0.)
37 , fStartZ(0.)
38 , fStartT(0.)
39 , fNPoints(0)
40{
41}
42// -------------------------------------------------------------------------
43
44
45// ----- Standard constructor ------------------------------------------
46CbmMCTrack::CbmMCTrack(int32_t pdgCode, int32_t motherId, double px, double py, double pz, double x, double y, double z,
47 double t, int32_t nPoints = 0)
48 : TObject()
49 , fProcessId(kPNoProcess)
50 , fPdgCode(pdgCode)
51 , fMotherId(motherId)
52 , fPx(px)
53 , fPy(py)
54 , fPz(pz)
55 , fE(-1.)
56 , fStartX(x)
57 , fStartY(y)
58 , fStartZ(z)
59 , fStartT(t)
60 , fNPoints(0)
61{
62 if (nPoints >= 0) fNPoints = nPoints;
63 // else fNPoints = 0;
64}
65// -------------------------------------------------------------------------
66
67
68// ----- Copy constructor ----------------------------------------------
70 : TObject(track)
71 , fProcessId(track.fProcessId)
72 , fPdgCode(track.fPdgCode)
73 , fMotherId(track.fMotherId)
74 , fPx(track.fPx)
75 , fPy(track.fPy)
76 , fPz(track.fPz)
77 , fE(track.GetEnergy())
78 , fStartX(track.fStartX)
79 , fStartY(track.fStartY)
80 , fStartZ(track.fStartZ)
81 , fStartT(track.fStartT)
82 , fNPoints(track.fNPoints)
83{
84 // *this = track;
85}
86// -------------------------------------------------------------------------
87
88
89// ----- Constructor from TParticle ------------------------------------
90CbmMCTrack::CbmMCTrack(TParticle* part)
91 : TObject()
92 , fProcessId(part->GetUniqueID())
93 , fPdgCode(part->GetPdgCode())
94 , fMotherId(part->GetMother(0))
95 , fPx(part->Px())
96 , fPy(part->Py())
97 , fPz(part->Pz())
98 , fE(part->Energy())
99 , fStartX(part->Vx())
100 , fStartY(part->Vy())
101 , fStartZ(part->Vz())
102 , fStartT(part->T() * 1e09)
103 , fNPoints(0)
104{
105}
106// -------------------------------------------------------------------------
107
108
109// ----- Destructor ----------------------------------------------------
111// -------------------------------------------------------------------------
112
113
114// ----- Public method GetMass -----------------------------------------
116{
117
118 if (TDatabasePDG::Instance()) {
119 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
120
121 // Particle found in TDatabasePDG
122 if (particle) return particle->Mass();
123
124 // Ions may not be in the TDatabasePDG, but their mass number is encoded
125 // in the PDG code like 10LZZZAAAI, where L is strangeness, Z is charge,
126 // A is number of nucleons, and I is isomer level.
127 else if (fPdgCode > 1000000000) {
128 int32_t a = (fPdgCode % 10000) / 10;
129 return double(a) * CbmProtonMass();
130 }
131
132 // Cherenkov photons
133 else if (fPdgCode == 50000050)
134 return 0.;
135
136 // Unknown particle type
137 else {
138 LOG(error) << "CbmMCTrack: Unknown PDG code " << fPdgCode;
139 return 0.;
140 }
141 } //? Instance of TDatabasePDG
142
143 LOG(fatal) << "CbmMCTrack: No TDatabasePDG";
144 return -1.;
145}
146// -------------------------------------------------------------------------
147
148
149// ----- Public method GetCharge ---------------------------------------
151{
152
153 if (TDatabasePDG::Instance()) {
154 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
155
156 // Particle found in TDatabasePDG
157 if (particle) {
158 double electron_charge = abs(TDatabasePDG::Instance()->GetParticle(11)->Charge());
159 return particle->Charge() / electron_charge;
160 }
161
162 // Ions may not be in the TDatabasePDG, but their charge number is encoded
163 // in the PDG code like 10LZZZAAAI, where L is strangeness, Z is charge,
164 // A is number of nucleons, and I is isomer level.
165 else if (fPdgCode > 1000000000) {
166 return double((fPdgCode % 10000000) / 10000);
167 }
168
169 // Cherenkov photons
170 else if (fPdgCode == 50000050)
171 return 0.;
172
173 // Unknown particle type
174 else {
175 LOG(error) << "CbmMCTrack: Unknown PDG code " << fPdgCode;
176 return 0.;
177 }
178 } //? Instance of TDatabasePDG
179
180 LOG(fatal) << "CbmMCTrack: No TDatabasePDG";
181 return 0.;
182}
183// -------------------------------------------------------------------------
184
185
186// ----- Public method GetRapidity -------------------------------------
188{
189 double e = GetEnergy();
190 double y = 0.5 * log((e + fPz) / (e - fPz));
191 return y;
192}
193// -------------------------------------------------------------------------
194
195
196// ----- Public method GetNPoints --------------------------------------
198{
199 if (detId == ECbmModuleId::kRef)
200 return (fNPoints & 1);
201 else if (detId == ECbmModuleId::kMvd)
202 return ((fNPoints & (7 << 1)) >> 1);
203 else if (detId == ECbmModuleId::kSts)
204 return ((fNPoints & (31 << 4)) >> 4);
205 else if (detId == ECbmModuleId::kRich)
206 return ((fNPoints & (1 << 9)) >> 9);
207 // The much (Muon Chambers) as well as the must (Muon Straws)
208 // are part of the muon detector subsystem, so points from both
209 // detector implementations are added to the same system
210 // Here the same number is returned for much and must
211 else if (detId == ECbmModuleId::kMuch || detId == ECbmModuleId::kMust)
212 return ((fNPoints & (31 << 10)) >> 10);
213 else if (detId == ECbmModuleId::kTrd)
214 return ((fNPoints & (31 << 15)) >> 15);
215 else if (detId == ECbmModuleId::kTof)
216 return ((fNPoints & (15 << 20)) >> 20);
217 else if (detId == ECbmModuleId::kPsd)
218 return ((fNPoints & (1 << 25)) >> 25);
219 else if (detId == ECbmModuleId::kFsd)
220 return ((fNPoints & (1 << 26)) >> 26);
221 else {
222 LOG(error) << "GetNPoints: Unknown detector ID " << detId;
223 return 0;
224 }
225}
226// -------------------------------------------------------------------------
227
228
229// ----- Public method SetNPoints --------------------------------------
230void CbmMCTrack::SetNPoints(ECbmModuleId iDet, int32_t nPoints)
231{
232
233 if (iDet == ECbmModuleId::kRef) {
234 if (nPoints < 0)
235 nPoints = 0;
236 else if (nPoints > 1)
237 nPoints = 1;
238 fNPoints = (fNPoints & (~1)) | nPoints;
239 }
240
241 else if (iDet == ECbmModuleId::kMvd) {
242 if (nPoints < 0)
243 nPoints = 0;
244 else if (nPoints > 7)
245 nPoints = 7;
246 fNPoints = (fNPoints & (~(7 << 1))) | (nPoints << 1);
247 }
248
249 else if (iDet == ECbmModuleId::kSts) {
250 if (nPoints < 0)
251 nPoints = 0;
252 else if (nPoints > 31)
253 nPoints = 31;
254 fNPoints = (fNPoints & (~(31 << 4))) | (nPoints << 4);
255 }
256
257 else if (iDet == ECbmModuleId::kRich) {
258 if (nPoints < 0)
259 nPoints = 0;
260 else if (nPoints > 1)
261 nPoints = 1;
262 fNPoints = (fNPoints & (~(1 << 9))) | (nPoints << 9);
263 }
264
265 // The much (Muon Chambers) as well as the must (Muon Straws)
266 // are part of the muon detector subsystem, so points from both
267 // detector implementations are added to the same system
268 // The info is stored in the same bit range
269 else if (iDet == ECbmModuleId::kMuch || iDet == ECbmModuleId::kMust) {
270 // First get the number of points already stored. Since the number are
271 // the added values of much and must the second call must update the
272 // existing value
273 int32_t alreadyStoredPoints = GetNPoints(iDet);
274 int32_t totalPoints = alreadyStoredPoints + nPoints;
275 if (totalPoints < 0)
276 totalPoints = 0;
277 else if (totalPoints > 31)
278 totalPoints = 31;
279 fNPoints = (fNPoints & (~(31 << 10))) | (totalPoints << 10);
280 }
281
282 else if (iDet == ECbmModuleId::kTrd) {
283 if (nPoints < 0)
284 nPoints = 0;
285 else if (nPoints > 31)
286 nPoints = 31;
287 fNPoints = (fNPoints & (~(31 << 15))) | (nPoints << 15);
288 }
289
290 else if (iDet == ECbmModuleId::kTof) {
291 if (nPoints < 0)
292 nPoints = 0;
293 else if (nPoints > 15)
294 nPoints = 15;
295 fNPoints = (fNPoints & (~(15 << 20))) | (nPoints << 20);
296 }
297
298 else if (iDet == ECbmModuleId::kPsd) {
299 if (nPoints < 0)
300 nPoints = 0;
301 else if (nPoints > 1)
302 nPoints = 1;
303 fNPoints = (fNPoints & (~(1 << 25))) | (nPoints << 25);
304 }
305
306 else if (iDet == ECbmModuleId::kFsd) {
307 if (nPoints < 0)
308 nPoints = 0;
309 else if (nPoints > 1)
310 nPoints = 1;
311 fNPoints = (fNPoints & (~(1 << 26))) | (nPoints << 26);
312 }
313
314 else
315 LOG(error) << "Unknown detector ID " << iDet;
316}
317// -------------------------------------------------------------------------
318
319
320// ----- String output -------------------------------------------------
321std::string CbmMCTrack::ToString() const
322{
323 stringstream ss;
324 ss << "MCTrack: mother " << fMotherId << ", GeantProcess " << TMCProcessName[fProcessId] << ", Type " << fPdgCode
325 << ", momentum (" << fPx << ", " << fPy << ", " << fPz << ") GeV" << std::endl;
326 ss << " Ref " << GetNPoints(ECbmModuleId::kRef) << ", MVD " << GetNPoints(ECbmModuleId::kMvd) << ", STS "
327 << GetNPoints(ECbmModuleId::kSts) << ", RICH " << GetNPoints(ECbmModuleId::kRich) << ", MUCH+MUST "
328 << GetNPoints(ECbmModuleId::kMuch) << ", TRD " << GetNPoints(ECbmModuleId::kTrd) << ", TOF "
329 << GetNPoints(ECbmModuleId::kTof) << ", PSD " << GetNPoints(ECbmModuleId::kPsd) << ", FSD "
330 << GetNPoints(ECbmModuleId::kFsd) << std::endl;
331 return ss.str();
332}
333// -------------------------------------------------------------------------
334
335
ClassImp(CbmConverterManager)
double CbmProtonMass()
Definition CbmDefs.h:259
ECbmModuleId
Enumerator for module Identifiers.
Definition CbmDefs.h:45
@ kMvd
Micro-Vertex Detector.
Definition CbmDefs.h:47
@ kTrd
Transition Radiation Detector.
Definition CbmDefs.h:51
@ kTof
Time-of-flight Detector.
Definition CbmDefs.h:52
@ kPsd
Projectile spectator detector.
Definition CbmDefs.h:54
@ kSts
Silicon Tracking System.
Definition CbmDefs.h:48
@ kMust
MuSt detection system.
Definition CbmDefs.h:53
@ kRef
Reference plane.
Definition CbmDefs.h:46
@ kMuch
Muon detection system.
Definition CbmDefs.h:50
@ kFsd
Forward spectator detector.
Definition CbmDefs.h:59
@ kRich
Ring-Imaging Cherenkov Detector.
Definition CbmDefs.h:49
friend fvec log(const fvec &a)
std::string ToString() const
Double32_t fPx
Definition CbmMCTrack.h:128
double GetCharge() const
Charge of the associated particle.
Double32_t fPy
Definition CbmMCTrack.h:128
void SetNPoints(ECbmModuleId iDet, int32_t np)
int32_t fMotherId
Definition CbmMCTrack.h:125
Double32_t fStartZ
Definition CbmMCTrack.h:134
Double32_t fStartT
Definition CbmMCTrack.h:134
uint32_t fProcessId
Definition CbmMCTrack.h:119
Double32_t fE
Definition CbmMCTrack.h:131
virtual ~CbmMCTrack()
Double32_t fStartY
Definition CbmMCTrack.h:134
int32_t fNPoints
Definition CbmMCTrack.h:152
double GetMass() const
Mass of the associated particle.
Double32_t fPz
Definition CbmMCTrack.h:128
int32_t GetPdgCode() const
Definition CbmMCTrack.h:67
Double32_t fStartX
Definition CbmMCTrack.h:134
double GetRapidity() const
int32_t GetNPoints(ECbmModuleId detId) const
double GetEnergy() const
Definition CbmMCTrack.h:161
int32_t fPdgCode
Definition CbmMCTrack.h:122