Project
Loading...
Searching...
No Matches
ExtendedTrack.cxx
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
17#include "TGeoGlobalMagField.h"
18#include <fmt/format.h>
19
20constexpr double muMass = 0.10565800;
21
22namespace o2::mch::eval
23{
25{
27 static bool isInitialized{false};
28 if (!isInitialized) {
29 if (!TGeoGlobalMagField::Instance()->GetField()) {
30 throw std::runtime_error("Magnetic field should have been initialized before this call to trackFitter()");
31 }
34 isInitialized = true;
35 }
36 return trackFitter;
37}
38
40 gsl::span<const Cluster>& clusters,
41 double x, double y, double z)
42{
43 auto s = clusters.subspan(track.getFirstClusterIdx(),
45
46 mClusters.assign(begin(s), end(s));
47 for (const auto& cluster : mClusters) {
48 mTrack.createParamAtCluster(cluster);
49 }
50
51 trackFitter().fit(mTrack);
52 extrapToVertex(x, y, z);
53}
54
55void ExtendedTrack::extrapToVertex(double x, double y, double z)
56{
58
59 // extrapolate to vertex
60 TrackParam trackParamAtVertex(mTrack.first()); // mTrack.first() = parameters at first cluster
61 TrackExtrap::extrapToVertex(trackParamAtVertex, x, y, z, 0., 0.);
62 mMomentum4D.SetPx(trackParamAtVertex.px());
63 mMomentum4D.SetPy(trackParamAtVertex.py());
64 mMomentum4D.SetPz(trackParamAtVertex.pz());
65 mMomentum4D.SetM(muMass);
66
67 // extrapolate to DCA
68 TrackParam trackParamAtDCA(mTrack.first());
70 double dcaX = trackParamAtDCA.getNonBendingCoor() - x;
71 double dcaY = trackParamAtDCA.getBendingCoor() - y;
72 mDCA = std::sqrt(dcaX * dcaX + dcaY * dcaY);
73
74 // extrapolate to the end of the absorber
75 TrackParam trackParam(mTrack.first());
76 TrackExtrap::extrapToZ(trackParam, -505.);
77 double xAbs = trackParam.getNonBendingCoor();
78 double yAbs = trackParam.getBendingCoor();
79 mRabs = std::sqrt(xAbs * xAbs + yAbs * yAbs);
80}
81
83{
84 return areEqual(*this, track, sChi2Max);
85}
86
88{
89 return mTrack.first();
90}
91
93{
94 return mTrack;
95}
96
98{
99 return areMatching(*this, track, sChi2Max);
100}
101
102bool areEqual(const ExtendedTrack& t1, const ExtendedTrack& t2, double chi2Max)
103{
104 const auto& clusters1 = t1.getClusters();
105 const auto& clusters2 = t2.getClusters();
106 if (clusters1.size() != clusters2.size()) {
107 return false;
108 }
109 for (size_t iCl = 0; iCl != clusters1.size(); ++iCl) {
110 const auto& cl1 = clusters1[iCl];
111 const auto& cl2 = clusters2[iCl];
112 if (cl1.getDEId() != cl2.getDEId()) {
113 return false;
114 }
115 double dx = cl1.getX() - cl2.getX();
116 double dy = cl1.getY() - cl2.getY();
117 double chi2 = dx * dx / (cl1.getEx2() + cl2.getEx2()) + dy * dy / (cl1.getEy2() + cl2.getEy2());
118 if (chi2 > chi2Max) {
119 return false;
120 }
121 }
122 return true;
123}
124
125bool areMatching(const ExtendedTrack& t1, const ExtendedTrack& t2, double chi2Max)
126{
127 size_t nMatchClusters(0);
128 bool matchCluster[10] = {false, false, false, false, false, false, false, false, false, false};
129
130 const auto& clusters1 = t1.getClusters();
131 const auto& clusters2 = t2.getClusters();
132
133 for (const auto& cl1 : clusters1) {
134 for (const auto& cl2 : clusters2) {
135 if (cl1.getDEId() == cl2.getDEId()) {
136 double dx = cl1.getX() - cl2.getX();
137 double dy = cl1.getY() - cl2.getY();
138 double chi2 = dx * dx / (cl1.getEx2() + cl2.getEx2()) + dy * dy / (cl1.getEy2() + cl2.getEy2());
139 if (chi2 <= chi2Max) {
140 matchCluster[cl1.getChamberId()] = true;
141 ++nMatchClusters;
142 break;
143 }
144 }
145 }
146 }
147
148 return ((matchCluster[0] || matchCluster[1] || matchCluster[2] || matchCluster[3]) &&
149 (matchCluster[6] || matchCluster[7] || matchCluster[8] || matchCluster[9]) &&
150 (2 * nMatchClusters > clusters1.size() || 2 * nMatchClusters > clusters2.size()));
151}
152
153std::ostream& operator<<(std::ostream& out, const ExtendedTrack& track)
154{
155 out << "{" << track.asString() << "}";
156 return out;
157}
158
160{
161 double chi2 = mTrack.first().getTrackChi2();
162 double ndf = 2.0 * mClusters.size() - 6;
163 return chi2 / ndf;
164}
165
166std::string ExtendedTrack::asString() const
167{
168 const auto& param = mTrack.first();
169 return fmt::format("x = {:7.2f}, y = {:7.2f}, z = {:7.2f}, px = {:7.2f}, py = {:7.2f}, pz = {:7.2f}, sign = {}",
170 param.getNonBendingCoor(), param.getBendingCoor(), param.getZ(),
171 param.px(), param.py(), param.pz(), param.getCharge());
172}
173} // namespace o2::mch::eval
Definition of the MCH cluster minimal structure.
constexpr double muMass
Definition of a class to fit a track to a set of clusters.
Definition of tools for track extrapolation.
Definition of the MCH track.
static void useExtrapV2(bool extrapV2=true)
Switch to Runge-Kutta extrapolation v2.
Definition TrackExtrap.h:50
static bool extrapToZ(TrackParam &trackParam, double zEnd)
static bool extrapToVertex(TrackParam &trackParam, double xVtx, double yVtx, double zVtx, double errXVtx, double errYVtx)
Definition TrackExtrap.h:61
static bool extrapToVertexWithoutBranson(TrackParam &trackParam, double zVtx)
Definition TrackExtrap.h:73
Class to fit a track to a set of clusters.
Definition TrackFitter.h:31
void smoothTracks(bool smooth)
Enable/disable the smoother (and the saving of related parameters)
Definition TrackFitter.h:47
void fit(Track &track, bool smooth=true, bool finalize=true, std::list< TrackParam >::reverse_iterator *itStartingParam=nullptr, bool skipLocalChi2Calculation=false)
MCH track external format.
Definition TrackMCH.h:34
track parameters for internal use
Definition TrackParam.h:34
Double_t getTrackChi2() const
return the chi2 of the track when the associated cluster was attached
Definition TrackParam.h:130
track for internal use
Definition Track.h:33
TrackParam & createParamAtCluster(const Cluster &cluster)
Definition Track.cxx:42
int getNClusters() const
Return the number of attached clusters.
Definition Track.h:44
const TrackParam & first() const
Return a reference to the track parameters at first cluster.
Definition Track.h:50
const TrackParam & param() const
bool isMatching(const ExtendedTrack &track) const
bool operator==(const ExtendedTrack &track) const
const std::vector< Cluster > & getClusters() const
ExtendedTrack(const TrackMCH &track, gsl::span< const Cluster > &clusters, double x, double y, double z)
const Track & track() const
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLuint end
Definition glcorearb.h:469
GLint y
Definition glcorearb.h:270
GLenum GLfloat param
Definition glcorearb.h:271
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition glcorearb.h:5034
bool areMatching(const ExtendedTrack &t1, const ExtendedTrack &t2, double chi2Max)
bool areEqual(const ExtendedTrack &t1, const ExtendedTrack &t2, double chi2Max)
TrackFitter & trackFitter()
std::ostream & operator<<(std::ostream &out, const ExtendedTrack &track)
std::vector< Cluster > clusters