er  dev
ERMCTrack.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "ERMCTrack.h"
9 
10 #include<iostream>
11 
12 #include "TParticle.h"
13 #ifndef ROOT_TParticlePDG
14  #include "TParticlePDG.h"
15 #endif
16 #ifndef ROOT_TDatabasePDG
17  #include "TDatabasePDG.h"
18 #endif
19 #include "FairRunSim.h"
20 
21 //-------------------------------------------------------------------------------------------------
23  : TObject(),
24  fPdgCode(0),
25  fMotherId(-1),
26  fPx(0.),
27  fPy(0.),
28  fPz(0.),
29  fStartX(0.),
30  fStartY(0.),
31  fStartZ(0.),
32  fStartT(0.),
33  fNPoints(0)
34 {
35 }
36 //-------------------------------------------------------------------------------------------------
37 ERMCTrack::ERMCTrack(Int_t pdgCode, Int_t motherId, Double_t px,
38  Double_t py, Double_t pz, Double_t x, Double_t y,
39  Double_t z, Double_t t, Int_t nPoints = 0)
40  : TObject(),
41  fPdgCode(pdgCode),
42  fMotherId(motherId),
43  fPx(px),
44  fPy(py),
45  fPz(pz),
46  fStartX(x),
47  fStartY(y),
48  fStartZ(z),
49  fStartT(t),
50  fNPoints(0)
51 {
52  if (nPoints >= 0) fNPoints = nPoints;
53  // else fNPoints = 0;
54  fPx = px;
55  fPy = py;
56  fPz = pz;
57  fMass = CalculateMass();
58  fEnergy = CalculateEnergy();
59 }
60 //-------------------------------------------------------------------------------------------------
62  : TObject(track),
63  fPdgCode(track.fPdgCode),
64  fMotherId(track.fMotherId),
65  fPx(track.fPx),
66  fPy(track.fPy),
67  fPz(track.fPz),
68  fStartX(track.fStartX),
69  fStartY(track.fStartY),
70  fStartZ(track.fStartZ),
71  fStartT(track.fStartT),
72  fNPoints(track.fNPoints),
73  fMass(track.fMass),
74  fEnergy(track.fEnergy)
75 {
76  // *this = track;
77 }
78 //-------------------------------------------------------------------------------------------------
79 ERMCTrack::ERMCTrack(TParticle* part)
80  : TObject(),
81  fPdgCode(part->GetPdgCode()),
82  fMotherId(part->GetMother(0)),
83  fPx(part->Px()),
84  fPy(part->Py()),
85  fPz(part->Pz()),
86  fStartX(part->Vx()),
87  fStartY(part->Vy()),
88  fStartZ(part->Vz()),
89  fStartT(part->T()*1e09),
90  fNPoints(0),
91  //@TODO выплить этот костыль
92  fID(part->GetStatusCode())
93 {
94  fMomentum.SetXYZT(fPx,fPy,fPz,fEnergy);
95  fMass = CalculateMass();
96  fEnergy = CalculateEnergy();
97  fPhi = fMomentum.Phi();
98  fTheta = fMomentum.Theta();
99 }
100 //-------------------------------------------------------------------------------------------------
102 //-------------------------------------------------------------------------------------------------
103 void ERMCTrack::Print(Int_t trackId) const {
104  /*std::cout << "Track " << trackId << ", mother : " << fMotherId
105  << ", Type " << fPdgCode << ", momentum (" << fPx << ", "
106  << fPy << ", " << fPz << ") GeV" << std::endl;*/
107  //std::cout << " Ref " << GetNPoints(kREF) << std::endl;
108 }
109 //-------------------------------------------------------------------------------------------------
110 Double_t ERMCTrack::GetMass() const {
111  return fMass;
112 }
113 //-------------------------------------------------------------------------------------------------
114 Double_t ERMCTrack::GetCharge() const {
115  if ( TDatabasePDG::Instance() ) {
116  TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
117  if ( particle ) return particle->Charge();
118  else return 0.;
119  }
120  return 0.;
121 }
122 //-------------------------------------------------------------------------------------------------
123 Double_t ERMCTrack::GetRapidity() const {
124  Double_t e = GetEnergy();
125  Double_t y = 0.5 * TMath::Log( (e+fPz) / (e-fPz) );
126  return y;
127 }
128 //-------------------------------------------------------------------------------------------------
129 Int_t ERMCTrack::GetNPoints(DetectorId detId) const {
130  /* if ( detId == kREF ) return ( fNPoints & 1);
131  else if ( detId == kMVD ) return ( (fNPoints & ( 7 << 1) ) >> 1);
132  else if ( detId == kSTS ) return ( (fNPoints & (31 << 4) ) >> 4);
133  else if ( detId == kRICH ) return ( (fNPoints & ( 1 << 9) ) >> 9);
134  else if ( detId == kMUCH ) return ( (fNPoints & (31 << 10) ) >> 10);
135  else if ( detId == kTRD ) return ( (fNPoints & (31 << 15) ) >> 15);
136  else if ( detId == kTOF ) return ( (fNPoints & (15 << 20) ) >> 20);
137  else if ( detId == kECAL ) return ( (fNPoints & ( 1 << 24) ) >> 24);
138  else if ( detId == kPSD ) return ( (fNPoints & ( 1 << 25) ) >> 25);
139  else {
140  std::cerr << "GetNPoints: Unknown detector ID "
141  << detId << std::endl;
142  */
143  return 0;
144  //}
145 }
146 //-------------------------------------------------------------------------------------------------
147 void ERMCTrack::SetNPoints(Int_t iDet, Int_t nPoints) {
148 /*
149  if ( iDet == kREF ) {
150  if ( nPoints < 0 ) nPoints = 0;
151  else if ( nPoints > 1 ) nPoints = 1;
152  fNPoints = ( fNPoints & ( ~ 1 ) ) | nPoints;
153  }
154 
155  else if ( iDet == kMVD ) {
156  if ( nPoints < 0 ) nPoints = 0;
157  else if ( nPoints > 7 ) nPoints = 7;
158  fNPoints = ( fNPoints & ( ~ ( 7 << 1 ) ) ) | ( nPoints << 1 );
159  }
160 
161  else if ( iDet == kSTS ) {
162  if ( nPoints < 0 ) nPoints = 0;
163  else if ( nPoints > 31 ) nPoints = 31;
164  fNPoints = ( fNPoints & ( ~ ( 31 << 4 ) ) ) | ( nPoints << 4 );
165  }
166 
167  else if ( iDet == kRICH ) {
168  if ( nPoints < 0 ) nPoints = 0;
169  else if ( nPoints > 1 ) nPoints = 1;
170  fNPoints = ( fNPoints & ( ~ ( 1 << 9 ) ) ) | ( nPoints << 9 );
171  }
172 
173  else if ( iDet == kMUCH ) {
174  if ( nPoints < 0 ) nPoints = 0;
175  else if ( nPoints > 31 ) nPoints = 31;
176  fNPoints = ( fNPoints & ( ~ ( 31 << 10 ) ) ) | ( nPoints << 10 );
177  }
178 
179  else if ( iDet == kTRD ) {
180  if ( nPoints < 0 ) nPoints = 0;
181  else if ( nPoints > 31 ) nPoints = 31;
182  fNPoints = ( fNPoints & ( ~ ( 31 << 15 ) ) ) | ( nPoints << 15 );
183  }
184 
185  else if ( iDet == kTOF ) {
186  if ( nPoints < 0 ) nPoints = 0;
187  else if ( nPoints > 15 ) nPoints = 15;
188  fNPoints = ( fNPoints & ( ~ ( 15 << 20 ) ) ) | ( nPoints << 20 );
189  }
190 
191  else if ( iDet == kECAL ) {
192  if ( nPoints < 0 ) nPoints = 0;
193  else if ( nPoints > 1 ) nPoints = 1;
194  fNPoints = ( fNPoints & ( ~ ( 1 << 24 ) ) ) | ( nPoints << 24 );
195  }
196 
197  else if ( iDet == kPSD ) {
198  if ( nPoints < 0 ) nPoints = 0;
199  else if ( nPoints > 1 ) nPoints = 1;
200  fNPoints = ( fNPoints & ( ~ ( 1 << 25 ) ) ) | ( nPoints << 25 );
201  }
202 
203  else std::cerr << "Unknown detector ID "
204  << iDet << std::endl;
205 */
206 }
207 //-------------------------------------------------------------------------------------------------
208 TLorentzVector ERMCTrack::GetVector(){
209  fMomentum.SetXYZT(fPx,fPy,fPz,fEnergy);
210  return fMomentum;
211 }
212 //-------------------------------------------------------------------------------------------------
213 Double_t ERMCTrack::GetTheta(){
214  fMomentum.SetXYZT(fPx,fPy,fPz,fEnergy);
215  fTheta = fMomentum.Theta();
216  return fTheta;
217 }
218 //-------------------------------------------------------------------------------------------------
219 Double_t ERMCTrack::GetPhi(){
220  fMomentum.SetXYZT(fPx,fPy,fPz,fEnergy);
221  fPhi = fMomentum.Phi();
222  return fPhi;
223 }
224 //-------------------------------------------------------------------------------------------------
225 Double_t ERMCTrack::CalculateMass() {
226  if ( TDatabasePDG::Instance() ) {
227  TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
228  return particle->Mass();
229  }
230  return 0.;
231 }
232 //-------------------------------------------------------------------------------------------------
233 Double_t ERMCTrack::CalculateEnergy() {
234  return TMath::Sqrt(fMass*fMass + fPx*fPx + fPy*fPy + fPz*fPz );
235 }
236 //-------------------------------------------------------------------------------------------------
237 ClassImp(ERMCTrack)
Int_t fPdgCode
Definition: ERMCTrack.h:102
Int_t fMotherId
Definition: ERMCTrack.h:105
Int_t GetNPoints(DetectorId detId) const
Definition: ERMCTrack.cxx:129
Double32_t fStartX
Definition: ERMCTrack.h:111
Int_t GetPdgCode() const
Definition: ERMCTrack.h:64
Double32_t fPx
Definition: ERMCTrack.h:108
virtual ~ERMCTrack()
Definition: ERMCTrack.cxx:101
void Print(Int_t iTrack=0) const
Definition: ERMCTrack.cxx:103