EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmMCTrack.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmMCTrack.cxx
1 // -------------------------------------------------------------------------
2 // ----- CbmMCTrack source file -----
3 // ----- Created 03/08/04 by V. Friese -----
4 // -------------------------------------------------------------------------
5 #include "CbmMCTrack.h"
6 
7 #include "FairLogger.h"
8 
9 #include "TParticle.h"
10 #ifndef ROOT_TParticlePDG
11  #include "TParticlePDG.h"
12 #endif
13 #ifndef ROOT_TDatabasePDG
14  #include "TDatabasePDG.h"
15 #endif
16 
17 
18 
19 // ----- Default constructor -------------------------------------------
21  : TObject(),
22  fPdgCode(0),
23  fMotherId(-1),
24  fPx(0.),
25  fPy(0.),
26  fPz(0.),
27  fStartX(0.),
28  fStartY(0.),
29  fStartZ(0.),
30  fStartT(0.),
31  fNPoints(0)
32 {
33 }
34 // -------------------------------------------------------------------------
35 
36 
37 
38 // ----- Standard constructor ------------------------------------------
39 CbmMCTrack::CbmMCTrack(Int_t pdgCode, Int_t motherId, Double_t px,
40  Double_t py, Double_t pz, Double_t x, Double_t y,
41  Double_t z, Double_t t, Int_t nPoints = 0)
42  : TObject(),
43  fPdgCode(pdgCode),
44  fMotherId(motherId),
45  fPx(px),
46  fPy(py),
47  fPz(pz),
48  fStartX(x),
49  fStartY(y),
50  fStartZ(z),
51  fStartT(t),
52  fNPoints(0)
53 {
54  if (nPoints >= 0) fNPoints = nPoints;
55  // else fNPoints = 0;
56 }
57 // -------------------------------------------------------------------------
58 
59 
60 
61 // ----- Copy constructor ----------------------------------------------
63  : TObject(track),
64  fPdgCode(track.fPdgCode),
65  fMotherId(track.fMotherId),
66  fPx(track.fPx),
67  fPy(track.fPy),
68  fPz(track.fPz),
69  fStartX(track.fStartX),
70  fStartY(track.fStartY),
71  fStartZ(track.fStartZ),
72  fStartT(track.fStartT),
73  fNPoints(track.fNPoints)
74 {
75  // *this = track;
76 }
77 // -------------------------------------------------------------------------
78 
79 
80 
81 // ----- Constructor from TParticle ------------------------------------
83  : TObject(),
84  fPdgCode(part->GetPdgCode()),
85  fMotherId(part->GetMother(0)),
86  fPx(part->Px()),
87  fPy(part->Py()),
88  fPz(part->Pz()),
89  fStartX(part->Vx()),
90  fStartY(part->Vy()),
91  fStartZ(part->Vz()),
92  fStartT(part->T()*1e09),
93  fNPoints(0)
94 {
95 }
96 // -------------------------------------------------------------------------
97 
98 
99 
100 // ----- Destructor ----------------------------------------------------
102 // -------------------------------------------------------------------------
103 
104 
105 
106 // ----- Public method Print -------------------------------------------
107 void CbmMCTrack::Print(Int_t trackId) const {
108  LOG(DEBUG) << "Track " << trackId << ", mother : " << fMotherId
109  << ", Type " << fPdgCode << ", momentum (" << fPx << ", "
110  << fPy << ", " << fPz << ") GeV" << FairLogger::endl;
111  LOG(DEBUG) << " Ref " << GetNPoints(kREF)
112  << ", MVD " << GetNPoints(kMVD)
113  << ", STS " << GetNPoints(kSTS)
114  << ", RICH " << GetNPoints(kRICH)
115  << ", MUCH " << GetNPoints(kMUCH)
116  << ", TRD " << GetNPoints(kTRD)
117  << ", TOF " << GetNPoints(kTOF)
118  << ", ECAL " << GetNPoints(kECAL)
119  << ", PSD " << GetNPoints(kPSD) << FairLogger::endl;
120 }
121 // -------------------------------------------------------------------------
122 
123 
124 
125 // ----- Public method GetMass -----------------------------------------
126 Double_t CbmMCTrack::GetMass() const {
127  if ( TDatabasePDG::Instance() ) {
128  TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
129  if ( particle ) return particle->Mass();
130  else return 0.;
131  }
132  return 0.;
133 }
134 // -------------------------------------------------------------------------
135 
136 
137 
138 
139 // ----- Public method GetRapidity -------------------------------------
140 Double_t CbmMCTrack::GetRapidity() const {
141  Double_t e = GetEnergy();
142  Double_t y = 0.5 * TMath::Log( (e+fPz) / (e-fPz) );
143  return y;
144 }
145 // -------------------------------------------------------------------------
146 
147 
148 
149 
150 // ----- Public method GetNPoints --------------------------------------
151 Int_t CbmMCTrack::GetNPoints(DetectorId detId) const {
152  if ( detId == kREF ) return ( fNPoints & 1);
153  else if ( detId == kMVD ) return ( (fNPoints & ( 7 << 1) ) >> 1);
154  else if ( detId == kSTS ) return ( (fNPoints & (31 << 4) ) >> 4);
155  else if ( detId == kRICH ) return ( (fNPoints & ( 1 << 9) ) >> 9);
156  else if ( detId == kMUCH ) return ( (fNPoints & (31 << 10) ) >> 10);
157  else if ( detId == kTRD ) return ( (fNPoints & (31 << 15) ) >> 15);
158  else if ( detId == kTOF ) return ( (fNPoints & (15 << 20) ) >> 20);
159  else if ( detId == kECAL ) return ( (fNPoints & ( 1 << 24) ) >> 24);
160  else if ( detId == kPSD ) return ( (fNPoints & ( 1 << 25) ) >> 25);
161  else {
162  LOG(ERROR) << "GetNPoints: Unknown detector ID "
163  << detId << FairLogger::endl;
164  return 0;
165  }
166 }
167 // -------------------------------------------------------------------------
168 
169 
170 
171 // ----- Public method SetNPoints --------------------------------------
172 void CbmMCTrack::SetNPoints(Int_t iDet, Int_t nPoints) {
173 
174  if ( iDet == kREF ) {
175  if ( nPoints < 0 ) nPoints = 0;
176  else if ( nPoints > 1 ) nPoints = 1;
177  fNPoints = ( fNPoints & ( ~ 1 ) ) | nPoints;
178  }
179 
180  else if ( iDet == kMVD ) {
181  if ( nPoints < 0 ) nPoints = 0;
182  else if ( nPoints > 7 ) nPoints = 7;
183  fNPoints = ( fNPoints & ( ~ ( 7 << 1 ) ) ) | ( nPoints << 1 );
184  }
185 
186  else if ( iDet == kSTS ) {
187  if ( nPoints < 0 ) nPoints = 0;
188  else if ( nPoints > 31 ) nPoints = 31;
189  fNPoints = ( fNPoints & ( ~ ( 31 << 4 ) ) ) | ( nPoints << 4 );
190  }
191 
192  else if ( iDet == kRICH ) {
193  if ( nPoints < 0 ) nPoints = 0;
194  else if ( nPoints > 1 ) nPoints = 1;
195  fNPoints = ( fNPoints & ( ~ ( 1 << 9 ) ) ) | ( nPoints << 9 );
196  }
197 
198  else if ( iDet == kMUCH ) {
199  if ( nPoints < 0 ) nPoints = 0;
200  else if ( nPoints > 31 ) nPoints = 31;
201  fNPoints = ( fNPoints & ( ~ ( 31 << 10 ) ) ) | ( nPoints << 10 );
202  }
203 
204  else if ( iDet == kTRD ) {
205  if ( nPoints < 0 ) nPoints = 0;
206  else if ( nPoints > 31 ) nPoints = 31;
207  fNPoints = ( fNPoints & ( ~ ( 31 << 15 ) ) ) | ( nPoints << 15 );
208  }
209 
210  else if ( iDet == kTOF ) {
211  if ( nPoints < 0 ) nPoints = 0;
212  else if ( nPoints > 15 ) nPoints = 15;
213  fNPoints = ( fNPoints & ( ~ ( 15 << 20 ) ) ) | ( nPoints << 20 );
214  }
215 
216  else if ( iDet == kECAL ) {
217  if ( nPoints < 0 ) nPoints = 0;
218  else if ( nPoints > 1 ) nPoints = 1;
219  fNPoints = ( fNPoints & ( ~ ( 1 << 24 ) ) ) | ( nPoints << 24 );
220  }
221 
222  else if ( iDet == kPSD ) {
223  if ( nPoints < 0 ) nPoints = 0;
224  else if ( nPoints > 1 ) nPoints = 1;
225  fNPoints = ( fNPoints & ( ~ ( 1 << 25 ) ) ) | ( nPoints << 25 );
226  }
227 
228  else LOG(ERROR) << "Unknown detector ID "
229  << iDet << FairLogger::endl;
230 
231 }
232 // -------------------------------------------------------------------------
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244