SND@LHC Software
Loading...
Searching...
No Matches
ShipMCTrack.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- ShipMCTrack source file -----
3// -------------------------------------------------------------------------
4#include "ShipMCTrack.h"
5
6#include "FairLogger.h" // for FairLogger, etc
7
8#include "TDatabasePDG.h" // for TDatabasePDG
9#include "TParticle.h" // for TParticle
10#include "TParticlePDG.h" // for TParticlePDG
11
12// ----- Default constructor -------------------------------------------
14 : TObject(),
15 fPdgCode(0),
16 fMotherId(-1),
17 fPx(0.),
18 fPy(0.),
19 fPz(0.),
20 fM(-1.),
21 fStartX(0.),
22 fStartY(0.),
23 fStartZ(0.),
24 fStartT(0.),
25 fNPoints(0),
26 fW(1.),
27 fProcID(44)
28{
29}
30// -------------------------------------------------------------------------
31
32
33
34// ----- Standard constructor ------------------------------------------
35ShipMCTrack::ShipMCTrack(Int_t pdgCode, Int_t motherId, Double_t px,
36 Double_t py, Double_t pz, Double_t M, Double_t x, Double_t y,
37 Double_t z, Double_t t, Int_t nPoints, Double_t w)
38 : TObject(),
39 fPdgCode(pdgCode),
40 fMotherId(motherId),
41 fPx(px),
42 fPy(py),
43 fPz(pz),
44 fM(M),
45 fStartX(x),
46 fStartY(y),
47 fStartZ(z),
48 fStartT(t),
49 fNPoints(nPoints),
50 fW(w)
51{
52}
53// -------------------------------------------------------------------------
54
55
56
57// ----- Copy constructor ----------------------------------------------
59 : TObject(track),
60 fPdgCode(track.fPdgCode),
61 fMotherId(track.fMotherId),
62 fPx(track.fPx),
63 fPy(track.fPy),
64 fPz(track.fPz),
65 fM(track.fM),
66 fStartX(track.fStartX),
67 fStartY(track.fStartY),
68 fStartZ(track.fStartZ),
69 fStartT(track.fStartT),
70 fNPoints(track.fNPoints),
71 fProcID(track.GetProcID()),
72 fW(track.GetWeight())
73{
74}
75// -------------------------------------------------------------------------
76
77
78
79// ----- Constructor from TParticle ------------------------------------
81 : TObject(),
82 fPdgCode(part->GetPdgCode()),
83 fMotherId(part->GetMother(0)),
84 fPx(part->Px()),
85 fPy(part->Py()),
86 fPz(part->Pz()),
87 fM([](const TParticle* p) {
88 Double_t m2 = p->Energy() * p->Energy() - p->P() * p->P();
89 if (m2 >= 0.) return TMath::Sqrt(m2);
90 // Tiny negative: numerical noise for on-shell massless particle
91 Double_t e2 = p->Energy() * p->Energy();
92 if (-m2 < 1e-10 * e2) return 0.;
93 // Genuinely spacelike (virtual photon): store negative mass (ROOT
94 // convention)
95 return -TMath::Sqrt(-m2);
96 }(part)),
97 fStartX(part->Vx()),
98 fStartY(part->Vy()),
99 fStartZ(part->Vz()),
100 fStartT(part->T()*1e09),
101 fNPoints(0),
102 fProcID(part->GetUniqueID()),
103 fW(part->GetWeight())
104{
105}
106// -------------------------------------------------------------------------
107
108
109
110// ----- Destructor ----------------------------------------------------
112// -------------------------------------------------------------------------
113
114
115
116// ----- Public method Print -------------------------------------------
117void ShipMCTrack::Print(Int_t trackId) const
118{
119 LOG(DEBUG) << "Track " << trackId << ", mother : " << fMotherId << ", Type "
120 << fPdgCode << ", momentum (" << fPx << ", " << fPy << ", "
121 << fPz << ") GeV" ;
122 /* LOG(DEBUG2) << " Ref " << GetNPoints(kREF)
123 << ", TutDet " << GetNPoints(kTutDet)
124 << ", Rutherford " << GetNPoints(kFairRutherford) ;
125*/
126}
127// -------------------------------------------------------------------------
128// ----- Public method GetEnergy -----------------------------------------
129
131{
132 if (fM<0){
133// older data, mass not made persistent
134 Double_t mass = GetMass();
135 return TMath::Sqrt(mass*mass + fPx*fPx + fPy*fPy + fPz*fPz );
136 }else{
137 if (fPdgCode==22){return TMath::Sqrt(fPx*fPx + fPy*fPy + fPz*fPz );}
138 return TMath::Sqrt(fM*fM + fPx*fPx + fPy*fPy + fPz*fPz );
139 }
140}
141// ----- Public method GetMass -----------------------------------------
142Double_t ShipMCTrack::GetMass() const
143{
144 if (fM<0){
145// older data, mass not made persistent
146 if ( TDatabasePDG::Instance() ) {
147 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
148 if ( particle ) { return particle->Mass(); }
149 else { return 0.; }
150 }
151 }else{
152 if (!std::isnan(fM)) { return fM; }
153 else{
154 if ( TDatabasePDG::Instance() ) {
155 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
156 if ( particle && !std::isnan(particle->Mass()) ) { return particle->Mass(); }
157 else { return 0.; }
158 }
159 }
160 }
161}
162// -------------------------------------------------------------------------
163
164
165// ----- Public method GetWeight -------------------------------------
167{
168 return fW;
169}
170// -------------------------------------------------------------------------
171
172
173// ----- Public method GetRapidity -------------------------------------
175{
176 Double_t e = GetEnergy();
177 Double_t y = 0.5 * TMath::Log( (e+fPz) / (e-fPz) );
178 return y;
179}
180// -------------------------------------------------------------------------
181
182
183
184
185// ----- Public method GetNPoints --------------------------------------
187{
188/* // TODO: Where does this come from
189 if ( detId == kREF ) { return ( fNPoints & 1); }
190 else if ( detId == kTutDet ) { return ( (fNPoints & ( 7 << 1) ) >> 1); }
191 else if ( detId == kFairRutherford ) { return ( (fNPoints & (31 << 4) ) >> 4); }
192 else {
193 LOG(ERROR) << "Unknown detector ID " << detId ;
194 return 0;
195 }
196*/
197 return 0;
198}
199// -------------------------------------------------------------------------
200
201
202
203// ----- Public method SetNPoints --------------------------------------
204void ShipMCTrack::SetNPoints(Int_t iDet, Int_t nPoints)
205{
206/*
207 if ( iDet == kREF ) {
208 if ( nPoints < 0 ) { nPoints = 0; }
209 else if ( nPoints > 1 ) { nPoints = 1; }
210 fNPoints = ( fNPoints & ( ~ 1 ) ) | nPoints;
211 }
212
213 else if ( iDet == kTutDet ) {
214 if ( nPoints < 0 ) { nPoints = 0; }
215 else if ( nPoints > 7 ) { nPoints = 7; }
216 fNPoints = ( fNPoints & ( ~ ( 7 << 1 ) ) ) | ( nPoints << 1 );
217 }
218
219 else if ( iDet == kFairRutherford ) {
220 if ( nPoints < 0 ) { nPoints = 0; }
221 else if ( nPoints > 31 ) { nPoints = 31; }
222 fNPoints = ( fNPoints & ( ~ ( 31 << 4 ) ) ) | ( nPoints << 4 );
223 }
224
225 else LOG(ERROR) << "Unknown detector ID " << iDet ;
226*/
227}
228// -------------------------------------------------------------------------
229
230
231
232
DetectorId
Double_t GetWeight() const
void Print(Int_t iTrack=0) const
Double32_t fPy
Int_t fPdgCode
Definition ShipMCTrack.h:96
Double_t GetRapidity() const
Double_t GetMass() const
Double32_t fW
Double32_t fM
Double_t GetEnergy() const
Int_t GetNPoints(DetectorId detId) const
void SetNPoints(Int_t iDet, Int_t np)
Int_t fMotherId
Definition ShipMCTrack.h:99
Double32_t fPz
virtual ~ShipMCTrack()
Double32_t fPx
ClassImp(ecalContFact) ecalContFact