CbmRoot
Loading...
Searching...
No Matches
CbmMCTrack.cxx
Go to the documentation of this file.
1/* Copyright (C) 2004-2021 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) return (fNPoints & 1);
200 else if (detId == ECbmModuleId::kMvd)
201 return ((fNPoints & (7 << 1)) >> 1);
202 else if (detId == ECbmModuleId::kSts)
203 return ((fNPoints & (31 << 4)) >> 4);
204 else if (detId == ECbmModuleId::kRich)
205 return ((fNPoints & (1 << 9)) >> 9);
206 else if (detId == ECbmModuleId::kMuch)
207 return ((fNPoints & (31 << 10)) >> 10);
208 else if (detId == ECbmModuleId::kTrd)
209 return ((fNPoints & (31 << 15)) >> 15);
210 else if (detId == ECbmModuleId::kTof)
211 return ((fNPoints & (15 << 20)) >> 20);
212 else if (detId == ECbmModuleId::kEcal)
213 return ((fNPoints & (1 << 24)) >> 24);
214 else if (detId == ECbmModuleId::kPsd)
215 return ((fNPoints & (1 << 25)) >> 25);
216 else if (detId == ECbmModuleId::kFsd)
217 return ((fNPoints & (1 << 26)) >> 26);
218 else {
219 LOG(error) << "GetNPoints: Unknown detector ID " << detId;
220 return 0;
221 }
222}
223// -------------------------------------------------------------------------
224
225
226// ----- Public method SetNPoints --------------------------------------
227void CbmMCTrack::SetNPoints(ECbmModuleId iDet, int32_t nPoints)
228{
229
230 if (iDet == ECbmModuleId::kRef) {
231 if (nPoints < 0) nPoints = 0;
232 else if (nPoints > 1)
233 nPoints = 1;
234 fNPoints = (fNPoints & (~1)) | nPoints;
235 }
236
237 else if (iDet == ECbmModuleId::kMvd) {
238 if (nPoints < 0) nPoints = 0;
239 else if (nPoints > 7)
240 nPoints = 7;
241 fNPoints = (fNPoints & (~(7 << 1))) | (nPoints << 1);
242 }
243
244 else if (iDet == ECbmModuleId::kSts) {
245 if (nPoints < 0) nPoints = 0;
246 else if (nPoints > 31)
247 nPoints = 31;
248 fNPoints = (fNPoints & (~(31 << 4))) | (nPoints << 4);
249 }
250
251 else if (iDet == ECbmModuleId::kRich) {
252 if (nPoints < 0) nPoints = 0;
253 else if (nPoints > 1)
254 nPoints = 1;
255 fNPoints = (fNPoints & (~(1 << 9))) | (nPoints << 9);
256 }
257
258 else if (iDet == ECbmModuleId::kMuch) {
259 if (nPoints < 0) nPoints = 0;
260 else if (nPoints > 31)
261 nPoints = 31;
262 fNPoints = (fNPoints & (~(31 << 10))) | (nPoints << 10);
263 }
264
265 else if (iDet == ECbmModuleId::kTrd) {
266 if (nPoints < 0) nPoints = 0;
267 else if (nPoints > 31)
268 nPoints = 31;
269 fNPoints = (fNPoints & (~(31 << 15))) | (nPoints << 15);
270 }
271
272 else if (iDet == ECbmModuleId::kTof) {
273 if (nPoints < 0) nPoints = 0;
274 else if (nPoints > 15)
275 nPoints = 15;
276 fNPoints = (fNPoints & (~(15 << 20))) | (nPoints << 20);
277 }
278
279 else if (iDet == ECbmModuleId::kEcal) {
280 if (nPoints < 0) nPoints = 0;
281 else if (nPoints > 1)
282 nPoints = 1;
283 fNPoints = (fNPoints & (~(1 << 24))) | (nPoints << 24);
284 }
285
286 else if (iDet == ECbmModuleId::kPsd) {
287 if (nPoints < 0) nPoints = 0;
288 else if (nPoints > 1)
289 nPoints = 1;
290 fNPoints = (fNPoints & (~(1 << 25))) | (nPoints << 25);
291 }
292
293 else if (iDet == ECbmModuleId::kFsd) {
294 if (nPoints < 0) nPoints = 0;
295 else if (nPoints > 1)
296 nPoints = 1;
297 fNPoints = (fNPoints & (~(1 << 26))) | (nPoints << 26);
298 }
299
300 else
301 LOG(error) << "Unknown detector ID " << iDet;
302}
303// -------------------------------------------------------------------------
304
305
306// ----- String output -------------------------------------------------
307std::string CbmMCTrack::ToString() const
308{
309 stringstream ss;
310 ss << "MCTrack: mother " << fMotherId << ", GeantProcess " << TMCProcessName[fProcessId] << ", Type " << fPdgCode
311 << ", momentum (" << fPx << ", " << fPy << ", " << fPz << ") GeV" << std::endl;
312 ss << " Ref " << GetNPoints(ECbmModuleId::kRef) << ", MVD " << GetNPoints(ECbmModuleId::kMvd) << ", STS "
313 << GetNPoints(ECbmModuleId::kSts) << ", RICH " << GetNPoints(ECbmModuleId::kRich) << ", MUCH "
314 << GetNPoints(ECbmModuleId::kMuch) << ", TRD " << GetNPoints(ECbmModuleId::kTrd) << ", TOF "
315 << GetNPoints(ECbmModuleId::kTof) << ", ECAL " << GetNPoints(ECbmModuleId::kEcal) << ", PSD "
316 << GetNPoints(ECbmModuleId::kPsd) << ", FSD " << GetNPoints(ECbmModuleId::kFsd) << std::endl;
317 return ss.str();
318}
319// -------------------------------------------------------------------------
320
321
ClassImp(CbmConverterManager)
double CbmProtonMass()
Definition CbmDefs.h:197
ECbmModuleId
Definition CbmDefs.h:39
@ kMvd
Micro-Vertex Detector.
@ kEcal
EM-Calorimeter.
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kRef
Reference plane.
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
friend fvec log(const fvec &a)
std::string ToString() const
Double32_t fPx
Definition CbmMCTrack.h:129
double GetCharge() const
Charge of the associated particle.
Double32_t fPy
Definition CbmMCTrack.h:129
void SetNPoints(ECbmModuleId iDet, int32_t np)
int32_t fMotherId
Definition CbmMCTrack.h:126
uint32_t fProcessId
Definition CbmMCTrack.h:120
virtual ~CbmMCTrack()
int32_t fNPoints
Definition CbmMCTrack.h:153
double GetMass() const
Mass of the associated particle.
Double32_t fPz
Definition CbmMCTrack.h:129
double GetRapidity() const
int32_t GetNPoints(ECbmModuleId detId) const
double GetEnergy() const
Definition CbmMCTrack.h:162
int32_t fPdgCode
Definition CbmMCTrack.h:123