FairShip
Loading...
Searching...
No Matches
MuonPath.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#ifndef NEWMUONDIS_MUONPATH_H_
6#define NEWMUONDIS_MUONPATH_H_
7
8#include <algorithm>
9#include <string>
10#include <vector>
11
12#include "ShipUnit.h"
13#include "TDatabasePDG.h"
14#include "TVector3.h"
15
16/*
17This class allows to consider a track with changes in directions between the
18different points of measurements (start, veto detectors, SST, etc...).
19
20A MuonPath can be made of several slices. For each slice, there is a start and
21an end position.
22
23When getting a random z position along the path, the extrapolation is made
24linearly using a vertex position which corresponds to the relevant point of
25measurement along the trajectory.
26*/
27
28// muon mass in GeV, from the PDG table
29inline double MuonMass() {
30 static const double mass = TDatabasePDG::Instance()->GetParticle(13)->Mass();
31 return mass;
32}
33
34class MuonPath {
35 public:
36 MuonPath();
38
39 inline void AddVolume(const std::string& aVol, const std::string& aMat,
40 const double& aD) {
41 flabel = GetLabel(aVol, aMat);
42 fvolName.push_back(aVol);
43 fmaterial.push_back(aMat);
44 fdensity = aD;
45 };
46
47 inline double GetMomentum(const unsigned& idx) const {
48 if (idx >= GetNSlices()) return 0;
49 return fpvec[idx].Mag();
50 };
51
52 inline double Getpx(const unsigned& idx) const {
53 if (idx >= GetNSlices()) return 0;
54 return fpvec[idx].X();
55 };
56
57 inline double Getpy(const unsigned& idx) const {
58 if (idx >= GetNSlices()) return 0;
59 return fpvec[idx].Y();
60 };
61
62 inline double Getpz(const unsigned& idx) const {
63 if (idx >= GetNSlices()) return 0;
64 return fpvec[idx].Z();
65 };
66
67 inline std::string GetLabel() const { return flabel; };
68
69 inline void SetLabel(const std::string& aLab) { flabel = aLab; };
70
71 inline double GetDensity() const { return fdensity; };
72
73 inline double GetWeightedDensity() const { return fwdensity; };
74
75 double GetWeightedDensity(double minLength) const;
76
77 inline void SetDensity(const double& aD) { fdensity = aD; };
78
79 inline double GetLength() const { return flength; };
80
81 inline double GetZLength() const { return fzlength; };
82
83 inline void SetLength(const double& aStep, const TVector3& aStart,
84 const double& aZ) {
85 flength += aStep;
86 fendLength.push_back(flength);
87 fzlength += aZ;
88 fstart.push_back(aStart);
89 fendZ.push_back(aStart.Z() + aZ);
90 fwdensity += aStep * fdensity;
91 fsliceDensity.push_back(fdensity);
92 const unsigned idx = static_cast<unsigned>(fstart.size() - 1);
93 fstartT.push_back(0.);
94 fstartT.back() = GetTimeNs(aStart.Z(), idx);
95 };
96
97 inline unsigned GetNSlices() const {
98 return static_cast<unsigned>(
99 std::min({fvolName.size(), fmaterial.size(), fpvec.size(), fvtx.size(),
100 fvtxT.size(), fstart.size(), fstartT.size(), fendZ.size()}));
101 };
102
103 inline double GetstartZ() const {
104 return fstart.empty() ? 0. : fstart.front().Z();
105 };
106
107 inline double GetstartX(const unsigned& idx) const {
108 if (idx >= GetNSlices()) return 0;
109 return fstart[idx].X();
110 };
111
112 inline double GetstartY(const unsigned& idx) const {
113 if (idx >= GetNSlices()) return 0;
114 return fstart[idx].Y();
115 };
116
117 inline double GetstartZ(const unsigned& idx) const {
118 if (idx >= GetNSlices()) return 0;
119 return fstart[idx].Z();
120 };
121
122 inline double GetEndZ(const unsigned& idx) const {
123 if (idx >= GetNSlices()) return 0;
124 return fendZ[idx];
125 };
126
127 inline double GetSliceLength(const unsigned& idx) const {
128 if (idx >= GetNSlices()) return 0;
129 return fendLength[idx] - (idx == 0 ? 0. : fendLength[idx - 1]);
130 };
131
132 void SetVertexInfo(const TVector3& vecpos, const TVector3& vecp,
133 const double& time);
134 std::string GetLabel(const std::string& aVol, const std::string& aMat) const;
135 void Print();
136 double GetZ(const double& aZ, unsigned& idx) const;
137 double GetZAtLength(double length, unsigned& idx) const;
138 double GetLengthAtZ(const double& aZ) const;
139 bool Add(const MuonPath& aEle);
140
141 inline double GetX(const double& aZ, const unsigned& idx) const {
142 if (idx >= GetNSlices() || fpvec[idx].Z() == 0) return 0;
143 return fvtx[idx].X() +
144 (aZ - fvtx[idx].Z()) * fpvec[idx].X() / fpvec[idx].Z();
145 };
146
147 inline double GetY(const double& aZ, const unsigned& idx) const {
148 if (idx >= GetNSlices() || fpvec[idx].Z() == 0) return 0;
149 return fvtx[idx].Y() +
150 (aZ - fvtx[idx].Z()) * fpvec[idx].Y() / fpvec[idx].Z();
151 };
152
153 inline double GetLength(const double& aZ, const unsigned& idx) const {
154 if (idx >= GetNSlices()) return 0;
155 return TMath::Sqrt(TMath::Power(GetX(aZ, idx) - fvtx[idx].X(), 2) +
156 TMath::Power(GetY(aZ, idx) - fvtx[idx].Y(), 2) +
157 TMath::Power(aZ - fvtx[idx].Z(), 2)); // in cm
158 };
159
160 inline double GetTimeNs(const double& aZ, const unsigned& idx) const {
161 if (idx >= GetNSlices() || fpvec[idx].Z() == 0.) return 0;
162 double P = fpvec[idx].Mag();
163 if (P == 0.) return 0;
164 double v = ShipUnit::c_light * P /
165 TMath::Sqrt(TMath::Power(P, 2) + TMath::Power(MuonMass(), 2));
166 if (v == 0.) return 0;
167 // A slice may precede its reference measurement in z.
168 return fvtxT[idx] + (aZ - fvtx[idx].Z()) * P / fpvec[idx].Z() / v;
169 };
170
171 private:
172 std::string flabel;
173 double fdensity;
174 double fwdensity;
175 double flength;
176 double fzlength;
177
178 std::vector<std::string> fvolName;
179 std::vector<std::string> fmaterial;
180 std::vector<TVector3> fvtx;
181 std::vector<double> fvtxT;
182 std::vector<TVector3> fstart;
183 std::vector<double> fstartT;
184 std::vector<double> fendZ;
185 std::vector<double> fsliceDensity;
186 std::vector<double>
187 fendLength; // cumulative segment lengths, excluding jumps
188 std::vector<TVector3> fpvec;
189};
190
191#endif // NEWMUONDIS_MUONPATH_H_
double MuonMass()
Definition MuonPath.h:29
double flength
Definition MuonPath.h:175
double GetstartY(const unsigned &idx) const
Definition MuonPath.h:112
double fzlength
Definition MuonPath.h:176
double GetLength() const
Definition MuonPath.h:79
void Print()
Definition MuonPath.cxx:130
double GetstartZ(const unsigned &idx) const
Definition MuonPath.h:117
double GetstartX(const unsigned &idx) const
Definition MuonPath.h:107
std::string GetLabel() const
Definition MuonPath.h:67
std::vector< TVector3 > fpvec
Definition MuonPath.h:188
void SetLabel(const std::string &aLab)
Definition MuonPath.h:69
double GetWeightedDensity() const
Definition MuonPath.h:73
std::vector< double > fsliceDensity
Definition MuonPath.h:185
double fdensity
Definition MuonPath.h:173
double GetX(const double &aZ, const unsigned &idx) const
Definition MuonPath.h:141
std::vector< std::string > fvolName
Definition MuonPath.h:178
unsigned GetNSlices() const
Definition MuonPath.h:97
std::vector< std::string > fmaterial
Definition MuonPath.h:179
std::string flabel
Definition MuonPath.h:172
double fwdensity
Definition MuonPath.h:174
void SetVertexInfo(const TVector3 &vecpos, const TVector3 &vecp, const double &time)
Definition MuonPath.cxx:20
double Getpz(const unsigned &idx) const
Definition MuonPath.h:62
void AddVolume(const std::string &aVol, const std::string &aMat, const double &aD)
Definition MuonPath.h:39
double GetSliceLength(const unsigned &idx) const
Definition MuonPath.h:127
std::vector< TVector3 > fvtx
Definition MuonPath.h:180
std::vector< double > fvtxT
Definition MuonPath.h:181
void SetDensity(const double &aD)
Definition MuonPath.h:77
double GetZ(const double &aZ, unsigned &idx) const
Definition MuonPath.cxx:68
double Getpy(const unsigned &idx) const
Definition MuonPath.h:57
std::vector< double > fendLength
Definition MuonPath.h:187
std::vector< TVector3 > fstart
Definition MuonPath.h:182
std::vector< double > fstartT
Definition MuonPath.h:183
double GetLength(const double &aZ, const unsigned &idx) const
Definition MuonPath.h:153
double GetEndZ(const unsigned &idx) const
Definition MuonPath.h:122
double GetTimeNs(const double &aZ, const unsigned &idx) const
Definition MuonPath.h:160
double GetLengthAtZ(const double &aZ) const
Definition MuonPath.cxx:57
double GetZLength() const
Definition MuonPath.h:81
double GetY(const double &aZ, const unsigned &idx) const
Definition MuonPath.h:147
double GetstartZ() const
Definition MuonPath.h:103
double GetMomentum(const unsigned &idx) const
Definition MuonPath.h:47
double GetDensity() const
Definition MuonPath.h:71
void SetLength(const double &aStep, const TVector3 &aStart, const double &aZ)
Definition MuonPath.h:83
double GetZAtLength(double length, unsigned &idx) const
Definition MuonPath.cxx:41
std::vector< double > fendZ
Definition MuonPath.h:184
double Getpx(const unsigned &idx) const
Definition MuonPath.h:52
bool Add(const MuonPath &aEle)
Definition MuonPath.cxx:156
~MuonPath()
Definition MuonPath.h:37
constexpr double c_light
Definition ShipUnit.h:44