Project
Loading...
Searching...
No Matches
TrackReference.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef ALICEO2_BASE_TRACKREFERENCE_H_
13#define ALICEO2_BASE_TRACKREFERENCE_H_
14
15#include <TVirtualMC.h>
16#include <ostream>
17#include "Rtypes.h" // for TrackReference::Class, ClassDef, etc
18#include "TMath.h" // for Pi, Sqrt, ATan2, Cos, Sin, ACos
19
20namespace o2
21{
22
23// class encoding sim track status
25 public:
28 kTrackInside = 0x1 << 1,
29 kTrackExiting = 0x1 << 2,
30 kTrackOut = 0x1 << 3,
31 kTrackStopped = 0x1 << 4,
32 kTrackAlive = 0x1 << 5,
33 kTrackNew = 0x1 << 6
34 };
35 SimTrackStatus() = default;
37 {
38 // This is quite annoying since every single call
39 // is virtual
40 if (vmc.IsTrackEntering()) {
41 mStatus |= kTrackEntering;
42 }
43 if (vmc.IsTrackExiting()) {
44 mStatus |= kTrackExiting;
45 }
46 if (vmc.IsTrackInside()) {
47 mStatus |= kTrackInside;
48 }
49 if (vmc.IsTrackOut()) {
50 mStatus |= kTrackOut;
51 }
52 if (vmc.IsTrackStop()) {
53 mStatus |= kTrackStopped;
54 }
55 if (vmc.IsNewTrack()) {
56 mStatus |= kTrackNew;
57 }
58 if (vmc.IsTrackAlive()) {
59 mStatus |= kTrackAlive;
60 }
61 }
62 bool isEntering() const { return mStatus & kTrackEntering; }
63 bool isInside() const { return mStatus & kTrackInside; }
64 bool isExiting() const { return mStatus & kTrackExiting; }
65 bool isOut() const { return mStatus & kTrackOut; }
66 bool isStopped() const { return mStatus & kTrackStopped; }
67 bool isAlive() const { return mStatus & kTrackAlive; }
68 bool isNew() const { return mStatus & kTrackNew; }
69 unsigned char getStatusWord() const { return mStatus; }
70
71 friend std::ostream& operator<<(std::ostream&, const SimTrackStatus&);
72
73 private:
74 unsigned char mStatus = 0;
75 ClassDefNV(SimTrackStatus, 1);
76};
77
81
88
89// NOTE: This track shares a lot of functionality with MC track and other tracks
90// which should be factored into a common base class
92{
93 public:
95 TrackReference() = default;
96
97 TrackReference(float x, float y, float z, float px, float py, float pz, float length, float tof, int trackID,
98 int detlabel);
99 TrackReference(const TVirtualMC& vmc, int detlabel);
100
102 ~TrackReference() = default;
103
104 Int_t getTrackID() const { return mTrackNumber; }
105 void setTrackID(Int_t track) { mTrackNumber = track; }
106 void setLength(float length) { mTrackLength = length; }
107 void setTime(float time) { mTof = time; }
108 float getLength() const { return mTrackLength; }
109 float getTime() const { return mTof; }
110 float R() const { return TMath::Sqrt(mX * mX + mY * mY); }
111
112 float Pt() const { return TMath::Sqrt(mPX * mPX + mPY * mPY); }
113 float PhiPos() const { return TMath::ATan2(mY, mX); }
114 float Phi() const { return TMath::ATan2(mPY, mPX); }
115 float Theta() const { return TMath::ACos(mPZ / P()); }
116 float X() const { return mX; }
117 float Y() const { return mY; }
118 float Z() const { return mZ; }
119 float Px() const { return mPX; }
120 float Py() const { return mPY; }
121 float Pz() const { return mPZ; }
122 float P() const { return TMath::Sqrt(mPX * mPX + mPY * mPY + mPZ * mPZ); }
123 Int_t getUserId() const { return mUserId; }
124 Int_t getDetectorId() const { return mDetectorId; }
125 void setDetectorId(Int_t id) { mDetectorId = id; }
126
127 void setPosition(float x, float y, float z)
128 {
129 mX = x;
130 mY = y;
131 mZ = z;
132 }
133
134 void setMomentum(float px, float py, float pz)
135 {
136 mPX = px;
137 mPY = py;
138 mPZ = pz;
139 }
140
141 void setUserId(Int_t userId) { mUserId = userId; }
142
143 // Methods to get position of the track reference in
144 // in the TPC/TRD/TOF Tracking coordinate system
145 float phiPosition() const { return TMath::Pi() + TMath::ATan2(-mY, -mX); }
146
147 float Alpha() const { return TMath::Pi() * (20 * ((((Int_t)(phiPosition() * 180 / TMath::Pi())) / 20)) + 10) / 180.; }
148
149 float LocalX() const
150 {
151 auto alpha = Alpha();
152 return mX * TMath::Cos(-alpha) - mY * TMath::Sin(-alpha);
153 }
154
155 float LocalY() const
156 {
157 auto alpha = Alpha();
158 return mX * TMath::Sin(-alpha) + mY * TMath::Cos(-alpha);
159 }
160
161 const SimTrackStatus& getTrackStatus() const { return mStatus; }
162
163 private:
164 Int_t mTrackNumber = 0;
165 float mX = 0;
166 float mY = 0;
167 float mZ = 0;
168 float mPX = 0;
169 float mPY = 0;
170 float mPZ = 0;
171 float mTrackLength = 0;
172 float mTof = 0;
173 Int_t mUserId = 0;
174 Int_t mDetectorId = 0;
175 SimTrackStatus mStatus;
176
177 friend std::ostream& operator<<(std::ostream&, const TrackReference&);
178
179 ClassDefNV(TrackReference, 1); // Base class for all Alice track references
180};
181
182// this is the preferred constructor as it might reuse variables
183// already fetched from VMC
184inline TrackReference::TrackReference(float x, float y, float z, float px, float py, float pz, float l, float tof,
185 int trackID, int detlabel)
186 : mTrackNumber(trackID),
187 mX(x),
188 mY(y),
189 mZ(z),
190 mPX(px),
191 mPY(py),
192 mPZ(pz),
193 mTrackLength(l),
194 mTof(tof),
195 mDetectorId(detlabel)
196{
197}
198
199// constructor fetching everything from vmc instance
200// less performant than other constructor since
201// potentially duplicated virtual function calls (already used in the
202// stepping functions)
203inline TrackReference::TrackReference(TVirtualMC const& vmc, int detlabel) : mStatus(vmc)
204{
205 float x, y, z;
206 float px, py, pz, e;
207 vmc.TrackPosition(x, y, z);
208 vmc.TrackMomentum(px, py, pz, e);
209 mX = x;
210 mY = y;
211 mZ = z;
212 mPX = px;
213 mPY = py;
214 mPZ = pz;
215 mTrackLength = vmc.TrackLength();
216 mTof = vmc.TrackTime();
217 mDetectorId = detlabel;
218 mTrackNumber = vmc.GetStack()->GetCurrentTrackNumber();
219}
220
221inline std::ostream& operator<<(std::ostream& os, const TrackReference& a)
222{
223 os << "TrackRef (" << a.mTrackNumber << "): X[" << a.mX << " , " << a.mY << " , " << a.mZ << "]"
224 << "; P[ " << a.mPX << " , " << a.mPY << " , " << a.mPZ << " ] "
225 << "; Length = " << a.mTrackLength << " ; TOF = " << a.mTof << " ; DetID = " << a.mDetectorId
226 << "; Status = " << a.mStatus;
227 return os;
228}
229
230inline std::ostream& operator<<(std::ostream& os, const SimTrackStatus& status)
231{
232 os << status.mStatus;
233 return os;
234}
235} // namespace o2
236
237#endif
int16_t time
Definition RawEventData.h:4
const SimTrackStatus & getTrackStatus() const
Int_t getUserId() const
float phiPosition() const
void setUserId(Int_t userId)
void setDetectorId(Int_t id)
float PhiPos() const
void setTime(float time)
~TrackReference()=default
Default Destructor.
Int_t getDetectorId() const
TrackReference()=default
Default Constructor.
float LocalY() const
friend std::ostream & operator<<(std::ostream &, const TrackReference &)
void setPosition(float x, float y, float z)
float getLength() const
float LocalX() const
void setMomentum(float px, float py, float pz)
float Theta() const
void setTrackID(Int_t track)
Int_t getTrackID() const
float getTime() const
float Alpha() const
void setLength(float length)
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLint GLenum GLint x
Definition glcorearb.h:403
GLint y
Definition glcorearb.h:270
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
SimTrackStatus(const TVirtualMC &vmc)
bool isAlive() const
unsigned char getStatusWord() const
bool isStopped() const
bool isInside() const
bool isExiting() const
SimTrackStatus()=default
bool isEntering() const
friend std::ostream & operator<<(std::ostream &, const SimTrackStatus &)