Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Track.cxx
1/*
2 * Track.cxx
3 *
4 * Created on: 23-06-2014
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "Track.h"
11
12#include "CompressionMap.h"
13#include "Cout.h"
14#include "DataFormat.h"
15#include "Event.h"
16
17#include <TMath.h>
18#include <TString.h>
19
20
21namespace Hal {
22
23 Track::Track() :
24 TObject(), fEvent(nullptr), fID(0), fStatus(0), fHiddenInfo(0), fMotherID(-1), fThisID(-1), fType(0), fCharge(0) {}
25
26 void Track::Print(Option_t* /*option*/) const {
27 Cout::Database({"Px", "Py", "Pz"});
28 Cout::Database({Form("%4.5f", GetPx()), Form("%4.5f", GetPy()), Form("%4.5f", GetPz())});
29 }
30
31 Track::~Track() {}
32
33 void Track::Boost(Double_t vx, Double_t vy, Double_t vz) { fP.Boost(vx, vy, vz); }
34
35 void Track::SetPrimary() {
36 SETBIT(fType, kPrimary);
37 CLRBIT(fType, kMother);
38 }
39
40 void Track::CopyData(Track* other) {
41 fP = other->fP;
42 fID = other->fID;
43 fStatus = other->fStatus;
44 fMotherID = other->fMotherID;
45 fCharge = other->fCharge;
46 fType = other->fType;
47 fHiddenInfo = -1;
48 if (IsV0()) {
49 fHiddenInfo = GetEvent()->fTotalV0s++;
50 V0Track* v0 = (V0Track*) GetEvent()->fV0sHiddenInfo->ConstructedAt(fHiddenInfo);
51 v0->CopyData(other->GetV0Info());
52 }
53 if (IsXi()) {
54 fHiddenInfo = GetEvent()->fTotalXis++;
55 XiTrack* xi = (XiTrack*) GetEvent()->fXisHiddenInfo->ConstructedAt(fHiddenInfo);
56 xi->CopyData(other->GetXiInfo());
57 }
58 }
59
60 void Track::CopyAllData(Track* other) {
61 fEvent = other->fEvent;
62 fThisID = other->fThisID;
63 CopyData(other);
64 }
65
66 Track::Track(const Track& track) : TObject(track) {
67 fEvent = track.fEvent;
68 fP = track.fP;
69 fID = track.fID;
70 fStatus = track.fStatus;
71 fMotherID = track.fMotherID;
72 fThisID = track.fThisID;
73 fType = track.fType;
74 fCharge = track.fCharge;
75 fHiddenInfo = track.fHiddenInfo;
76 }
77
78 std::vector<int> Track::GetLinks() const {
79 std::vector<int> links;
80 GetLinksFast(links, kFALSE);
81 return links;
82 }
83
84 Int_t Track::GetLinksFast(std::vector<int>& vec, Bool_t fast) const {
85 if (fast) {
86 Int_t size = 0;
87 vec[size++] = GetThisID();
88 if (IsGoodSecondary()) { vec[size++] = GetMotherIndex(); }
89 if (IsGoodV0()) {
90 V0Track* v0 = GetV0Info();
91 vec[size++] = v0->GetPosId();
92 vec[size++] = v0->GetNegId();
93 }
94 if (IsGoodXi()) {
95 XiTrack* xi = GetXiInfo();
96 vec[size++] = xi->GetV0Id();
97 vec[size++] = xi->GetChId();
98 int v0id = xi->GetV0Id();
99 auto v0track = GetEvent()->GetTrack(v0id);
100 if (v0track->IsGoodV0()) {
101 V0Track* v0 = v0track->GetV0Info();
102 vec[size++] = v0->GetPosId();
103 vec[size++] = v0->GetNegId();
104 }
105 }
106 return size;
107 } else {
108 vec.push_back(GetThisID());
109 if (IsGoodSecondary()) vec.push_back(GetMotherIndex());
110 if (IsGoodV0()) {
111 vec.push_back(GetV0Info()->GetPosId());
112 vec.push_back(GetV0Info()->GetNegId());
113 }
114 if (IsGoodXi()) {
115 XiTrack* xi = GetXiInfo();
116 vec.push_back(xi->GetV0Id());
117 vec.push_back(xi->GetChId());
118 auto v0track = GetEvent()->GetTrack(xi->GetV0Id());
119 if (v0track->IsGoodV0()) {
120 V0Track* v0 = v0track->GetV0Info();
121 vec.push_back(v0->GetPosId());
122 vec.push_back(v0->GetNegId());
123 }
124 }
125 return (int) vec.size();
126 }
127 }
128
131 if (IsGoodV0()) {
132 auto v0Info = GetV0Info();
133 v0Info->SetPosId(map.GetNewIndex(GetV0Info()->GetPosId()));
134 v0Info->SetNegId(map.GetNewIndex(GetV0Info()->GetNegId()));
135 v0Info->SetTrackId(GetThisID());
136 }
137 if (IsGoodXi()) {
138 auto xiInfo = GetXiInfo();
139 xiInfo->SetV0Id(map.GetNewIndex(GetXiInfo()->GetV0Id()));
140 xiInfo->SetChId(map.GetNewIndex(GetXiInfo()->GetChId()));
141 xiInfo->SetTrackId(GetThisID());
142 }
143 }
144
145 void Track::SetLinks(std::vector<int>& vec) {
146 this->SetThisID(vec[0]);
147 if (IsGoodSecondary()) {
148 SetMotherIndex(vec[1]);
149 if (IsGoodV0()) {
150 auto v0Info = GetV0Info();
151 v0Info->SetTrackId(GetThisID());
152 v0Info->SetPosId(vec[2]);
153 v0Info->SetNegId(vec[3]);
154 }
155 if (IsGoodXi()) {
156 auto xiInfo = GetXiInfo();
157 xiInfo->SetTrackId(GetThisID());
158 xiInfo->SetV0Id(vec[2]);
159 xiInfo->SetChId(vec[3]);
160 }
161 } else {
162 if (IsGoodV0()) {
163 auto v0Info = GetV0Info();
164 v0Info->SetTrackId(GetThisID());
165 v0Info->SetPosId(vec[1]);
166 v0Info->SetNegId(vec[2]);
167 }
168 if (IsGoodXi()) {
169 auto v0Info = GetXiInfo();
170 v0Info->SetTrackId(GetThisID());
171 v0Info->SetV0Id(vec[1]);
172 v0Info->SetChId(vec[2]);
173 }
174 }
175 }
176
177 void Track::SetMass(Double_t mass) {
178 Double_t p = GetMomentum().P();
179 Double_t e = TMath::Sqrt(p * p + mass * mass);
180 fP.SetE(e);
181 }
182
183 void Track::SetSecondary(Bool_t parent) {
184 CLRBIT(fType, kPrimary);
185 if (parent) {
186 SETBIT(fType, kMother);
187 } else {
188 CLRBIT(fType, kMother);
189 }
190 }
191
192 void Track::EnableV0(Bool_t v0, Bool_t good) {
193 if (v0) {
194 SETBIT(fType, kV0);
195 if (good)
196 SETBIT(fType, kV0Daughters);
197 else
198 CLRBIT(fType, kV0Daughters);
199 fHiddenInfo = fEvent->fTotalV0s;
200 fEvent->fV0sHiddenInfo->ConstructedAt(fEvent->fTotalV0s++);
201 } else {
202 CLRBIT(fType, kV0);
203 }
204 }
205
206 Float_t Track::GetFieldVal(Int_t fieldID) const {
207 switch (fieldID) {
208 case DataFieldID::Track::EBasic::kPx: return fP.Px(); break;
209 case DataFieldID::Track::EBasic::kPy: return fP.Py(); break;
210 case DataFieldID::Track::EBasic::kPz: return fP.Pz(); break;
211 case DataFieldID::Track::EBasic::kE: return fP.E(); break;
212 case DataFieldID::Track::EBasic::kPhi: return fP.Phi(); break;
213
214 case DataFieldID::Track::EBasic::kPt: return fP.Pt(); break;
215 case DataFieldID::Track::EBasic::kTheta: return fP.Theta(); break;
216 case DataFieldID::Track::EBasic::kP: return fP.P(); break;
217 case DataFieldID::Track::EBasic::kEta: return fP.Eta(); break;
218 case DataFieldID::Track::EBasic::kRapidity: return fP.Rapidity(); break;
219
220 case DataFieldID::Track::EBasic::kCharge: return GetCharge(); break;
221 case DataFieldID::Track::EBasic::kStatus: return GetStatus(); break;
222 case DataFieldID::Track::EBasic::kPq: return GetCharge() * fP.P(); break;
223 case DataFieldID::Track::EBasic::kTrackZero: return 0; break;
224
225 case DataFieldID::Track::EV0::kAssumedPdg: return GetV0IfPossible(fieldID); break;
226 case DataFieldID::Track::EV0::kAssumedPdgPos: return GetV0IfPossible(fieldID); break;
227 case DataFieldID::Track::EV0::kAssumedPdgNeg: return GetV0IfPossible(fieldID); break;
228 case DataFieldID::Track::EV0::kS1: return GetV0IfPossible(fieldID); break;
229 case DataFieldID::Track::EV0::kS2: return GetV0IfPossible(fieldID); break;
230 case DataFieldID::Track::EV0::kAlphaArm: return GetV0IfPossible(fieldID); break;
231 case DataFieldID::Track::EV0::kPtArm: return GetV0IfPossible(fieldID); break;
232 case DataFieldID::Track::EV0::kDauDist: return GetV0IfPossible(fieldID); break;
233 case DataFieldID::Track::EV0::kDecLenght: return GetV0IfPossible(fieldID); break;
234 case DataFieldID::Track::EV0::kCosAngle: return GetV0IfPossible(fieldID); break;
235 case DataFieldID::Track::EV0::kLambdaMass: return GetV0IfPossible(fieldID); break;
236 case DataFieldID::Track::EV0::kAntiLambdaMass: return GetV0IfPossible(fieldID); break;
237 case DataFieldID::Track::EV0::kK0Mass: return GetV0IfPossible(fieldID); break;
238 }
239 if (fieldID > DataFieldID::Internal::EventStart) { return GetEvent()->GetFieldVal(fieldID); }
240
241 return -FLT_MAX;
242 }
243
244 TString Track::GetFieldName(Int_t fieldID) const {
245 switch (fieldID) {
246 case DataFieldID::Track::EBasic::kPx: return "p_{x} [GeV/c]"; break;
247 case DataFieldID::Track::EBasic::kPy: return "p_{y} [GeV/c]"; break;
248 case DataFieldID::Track::EBasic::kPz: return "p_{z} [GeV/c]"; break;
249 case DataFieldID::Track::EBasic::kE: return "E [GeV/c^{2}]"; break;
250 case DataFieldID::Track::EBasic::kPhi: return "#phi [rad]"; break;
251
252 case DataFieldID::Track::EBasic::kPt: return "p_{T} [GeV/c]"; break;
253 case DataFieldID::Track::EBasic::kTheta: return "#theta [rad]"; break;
254 case DataFieldID::Track::EBasic::kP: return "p [GeV/c]"; break;
255 case DataFieldID::Track::EBasic::kEta: return "#eta [AU]"; break;
256 case DataFieldID::Track::EBasic::kRapidity: return "y [AU]"; break;
257
258 case DataFieldID::Track::EBasic::kCharge: return "q [e]"; break;
259 case DataFieldID::Track::EBasic::kStatus: return "stat [AU]"; break;
260 case DataFieldID::Track::EBasic::kPq: return "pq [GeV/c*e]"; break;
261
262 case DataFieldID::Track::EV0::kAssumedPdg: return "V0_{pidHypo} [PDG]"; break;
263 case DataFieldID::Track::EV0::kAssumedPdgPos: return "V0_{dau pos Hypo} [PDG]"; break;
264 case DataFieldID::Track::EV0::kAssumedPdgNeg: return "V0_{dau neg Hypo} [PDG]"; break;
265 case DataFieldID::Track::EV0::kS1: return "V0_{s1} [cm]"; break;
266 case DataFieldID::Track::EV0::kS2: return "V0_{s2} [cm]"; break;
267 case DataFieldID::Track::EV0::kAlphaArm: return "V0_{#alpha} [AU]"; break;
268 case DataFieldID::Track::EV0::kPtArm: return "V0_{pT} [AU]"; break;
269 case DataFieldID::Track::EV0::kDauDist: return "V0_{dau-dist} [cm]"; break;
270 case DataFieldID::Track::EV0::kDecLenght: return "V0_{L} [cm]"; break;
271 case DataFieldID::Track::EV0::kCosAngle: return "V0_{angle cos} [AU]"; break;
272 case DataFieldID::Track::EV0::kLambdaMass: return "V0_{m#Lambda} [GeV/c^{2}]"; break;
273 case DataFieldID::Track::EV0::kAntiLambdaMass: return "V0_{m#bar{#Lambda}} [GeV/c^{2}]"; break;
274 case DataFieldID::Track::EV0::kK0Mass: return "V0_{K_{0}^{2}} [GeV/c^{2}]"; break;
275 }
276 if (fieldID > DataFieldID::Internal::EventStart) { return GetEvent()->GetFieldName(fieldID); }
277 Cout::PrintInfo(Form("Track::GetFieldName cannot find field with fieldID %i", fieldID), EInfo::kLowWarning);
278 return "[]";
279 }
280
281 void Track::Clear(Option_t* /*opt*/) {
282 fMotherID = -1;
283 fHiddenInfo = -1;
284 fThisID = -1;
285 fType = 0;
286 fEvent = nullptr;
287 fID = -1;
288 }
289
291 if (!TESTBIT(fType, kV0)) return nullptr;
292 return (V0Track*) fEvent->fV0sHiddenInfo->UncheckedAt(fHiddenInfo);
293 }
294
295 void Track::ResetTrack(Int_t thisID, Event* event) {
296 fMotherID = -1;
297 fHiddenInfo = -1;
298 fThisID = thisID;
299 fType = 0;
300 fEvent = event;
301 fID = -1;
302 }
303
304 Float_t Track::GetV0IfPossible(Int_t fieldId) const {
305 Hal::V0Track* tr = GetV0Info();
306 if (tr == nullptr) return Hal::Const::DummyVal();
307 switch (fieldId) {
308 case DataFieldID::Track::EV0::kAssumedPdg: return tr->GetPdg(); break;
309 case DataFieldID::Track::EV0::kAssumedPdgPos: return tr->GetPdgPosDau(); break;
310 case DataFieldID::Track::EV0::kAssumedPdgNeg: return tr->GetPdgNegDau(); break;
311 case DataFieldID::Track::EV0::kS1: return tr->GetS().first; break;
312 case DataFieldID::Track::EV0::kS2: return tr->GetS().second; break;
313 case DataFieldID::Track::EV0::kAlphaArm: return tr->GetAlphaArm(); break;
314 case DataFieldID::Track::EV0::kPtArm: return tr->GetPtArm(); break;
315 case DataFieldID::Track::EV0::kDauDist: return tr->GetDauDist(); break;
316 case DataFieldID::Track::EV0::kDecLenght: return tr->GetDecLength(); break;
317 case DataFieldID::Track::EV0::kCosAngle: return tr->GetCosAngle(); break;
318 case DataFieldID::Track::EV0::kLambdaMass: return tr->GetLambdaMass(); break;
319 case DataFieldID::Track::EV0::kAntiLambdaMass: return tr->GetAntiLambdaMass(); break;
320 case DataFieldID::Track::EV0::kK0Mass: return tr->GetK0Mass(); break;
321 }
322 return -FLT_MIN;
323 }
324
325 void Track::RotateZ(Double_t angle) { fP.RotateZ(angle); }
326
327 void Track::EnableXi(Bool_t xi, Bool_t good) {
328 if (xi) {
329 SETBIT(fType, kXi);
330 if (good)
331 SETBIT(fType, kXiDaughters);
332 else
333 CLRBIT(fType, kXiDaughters);
334 fHiddenInfo = fEvent->fTotalXis;
335 fEvent->fXisHiddenInfo->ConstructedAt(fEvent->fTotalXis++);
336 } else {
337 CLRBIT(fType, kXi);
338 }
339 }
340
342 if (!TESTBIT(fType, kXi)) return nullptr;
343 return (XiTrack*) fEvent->fXisHiddenInfo->UncheckedAt(fHiddenInfo);
344 }
345
346} // namespace Hal
Int_t GetNewIndex(Int_t old_index) const
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
virtual Float_t GetFieldVal(Int_t fieldID) const
Definition Event.cxx:254
virtual TString GetFieldName(Int_t fieldID) const
Definition Event.cxx:272
Track * GetTrack(Int_t i) const
Definition Event.h:208
virtual void ResetTrack(Int_t thisID=-1, Event *event=nullptr)
Definition Track.cxx:295
void EnableV0(Bool_t v0, Bool_t daughters=kTRUE)
Definition Track.cxx:192
Int_t GetThisID() const
Definition Track.h:83
virtual void SetLinks(std::vector< int > &vec)
Definition Track.cxx:145
Float_t GetV0IfPossible(Int_t fieldId) const
Definition Track.cxx:304
void SetThisID(Int_t id)
Definition Track.h:78
Int_t GetStatus() const
Definition Track.h:199
void EnableXi(Bool_t xi, Bool_t daughters=kTRUE)
Definition Track.cxx:327
Event * GetEvent() const
Definition Track.h:315
V0Track * GetV0Info() const
Definition Track.cxx:290
void SetMass(Double_t mass)
Definition Track.cxx:177
const TLorentzVector & GetMomentum() const
Definition Track.h:118
virtual void RotateZ(Double_t angle)
Definition Track.cxx:325
Bool_t IsGoodV0() const
Definition Track.h:219
void TranslateLinks(const CompressionMap &map)
Definition Track.cxx:129
void SetSecondary(Bool_t parent)
Definition Track.cxx:183
TLorentzVector fP
don't stream it will be build on the fly
Definition Track.h:37
Event * fEvent
Definition Track.h:36
virtual Float_t GetFieldVal(Int_t fieldID) const
Definition Track.cxx:206
virtual TString GetFieldName(Int_t fieldID) const
Definition Track.cxx:244
Bool_t IsGoodXi() const
Definition Track.h:225
Bool_t IsGoodSecondary() const
Definition Track.h:214
void SetMotherIndex(Int_t index)
Definition Track.h:170
virtual void Clear(Option_t *opt="")
Definition Track.cxx:281
Int_t GetMotherIndex() const
Definition Track.h:204
XiTrack * GetXiInfo() const
Definition Track.cxx:341
std::vector< int > GetLinks() const
Definition Track.cxx:78
Double_t GetCharge() const
Definition Track.h:184
virtual Int_t GetLinksFast(std::vector< int > &vec, Bool_t fast=kTRUE) const
Definition Track.cxx:84
Double_t GetK0Mass() const
Definition V0Track.h:161
Double_t GetDecLength() const
Definition V0Track.h:103
Int_t GetNegId() const
Definition V0Track.h:78
Double_t GetPtArm() const
Definition V0Track.h:93
Int_t GetPdg() const
Definition V0Track.h:63
virtual void CopyData(V0Track *v)
Definition V0Track.cxx:70
Double_t GetAntiLambdaMass() const
Definition V0Track.h:156
Double_t GetAlphaArm() const
Definition V0Track.h:88
Double_t GetDauDist() const
Definition V0Track.h:98
Int_t GetPdgNegDau() const
Definition V0Track.h:73
Int_t GetPosId() const
Definition V0Track.h:83
std::pair< Double_t, Double_t > GetS() const
Definition V0Track.h:171
Int_t GetPdgPosDau() const
Definition V0Track.h:68
Double_t GetLambdaMass() const
Definition V0Track.h:151
Double_t GetCosAngle() const
Definition V0Track.h:108