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