Project
Loading...
Searching...
No Matches
CompareTracks.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
12#include "CompareTracks.h"
13#include "Histos.h"
14#include <TH1F.h>
15#include <TH2F.h>
16#include <TMath.h>
17
18namespace o2::mch::eval
19{
20
21void printResiduals(const TrackParam& param1, const TrackParam& param2)
22{
24 std::cout << "{dx = " << param2.getNonBendingCoor() - param1.getNonBendingCoor()
25 << ", dy = " << param2.getBendingCoor() - param1.getBendingCoor()
26 << ", dz = " << param2.getZ() - param1.getZ()
27 << ", dpx = " << (param2.px() - param1.px()) << " (" << 100. * (param2.px() - param1.px()) / param1.px() << "\%)"
28 << ", dpy = " << (param2.py() - param1.py()) << " (" << 100. * (param2.py() - param1.py()) / param1.py() << "\%)"
29 << ", dpz = " << (param2.pz() - param1.pz()) << " (" << 100. * (param2.pz() - param1.pz()) / param1.pz() << "\%)"
30 << ", dcharge = " << param2.getCharge() - param1.getCharge()
31 << "}" << std::endl;
32}
33
34void printCovResiduals(const TMatrixD& cov1, const TMatrixD& cov2)
35{
37 TMatrixD diff(cov2, TMatrixD::kMinus, cov1);
38 diff.Print();
39}
40
41int compareEvents(std::list<ExtendedTrack>& tracks1,
42 std::list<ExtendedTrack>& tracks2,
43 double precision,
44 bool printDiff,
45 bool printAll,
46 std::vector<TH1*>& trackResidualsAtFirstCluster,
47 std::vector<TH1*>& clusterClusterResiduals)
48{
50
51 int nDifferences(0);
52
53 // first look for identical tracks in the 2 events
54 for (auto& track1 : tracks1) {
55 // find a track in the second event identical to track1 and not already matched
56 auto itTrack2 = tracks2.begin();
57 do {
58 itTrack2 = find(itTrack2, tracks2.end(), track1);
59 } while (itTrack2 != tracks2.end() && itTrack2->hasMatchFound() && ++itTrack2 != tracks2.end());
60 if (itTrack2 != tracks2.end()) {
61 track1.setMatchFound(true);
62 itTrack2->setMatchFound(true);
63 track1.setMatchIdentical(true);
64 itTrack2->setMatchIdentical(true);
65 fillClusterClusterResiduals(track1, *itTrack2, clusterClusterResiduals);
66 // compare the track parameters
67 bool areParamCompatible = areCompatible(track1.param(), itTrack2->param(), precision);
68 bool areCovCompatible = areCompatible(track1.param().getCovariances(), itTrack2->param().getCovariances(), precision);
69 if (!areParamCompatible || !areCovCompatible) {
70 ++nDifferences;
71 }
72 if (printAll || (printDiff && !areParamCompatible)) {
73 printResiduals(track1.param(), itTrack2->param());
74 }
75 if (printAll || (printDiff && !areCovCompatible)) {
76 printCovResiduals(track1.param().getCovariances(), itTrack2->param().getCovariances());
77 }
78 fillTrackResiduals(track1.param(), itTrack2->param(), trackResidualsAtFirstCluster);
79 }
80 }
81
82 // then look for similar tracks in the 2 events
83 for (auto& track1 : tracks1) {
84 // skip already matched tracks
85 if (track1.hasMatchFound()) {
86 continue;
87 }
88 // find a track in the second event similar to track1 and not already matched
89 for (auto& track2 : tracks2) {
90 if (!track2.hasMatchFound() && track2.isMatching(track1)) {
91 track1.setMatchFound(true);
92 track2.setMatchFound(true);
93 fillClusterClusterResiduals(track1, track2, clusterClusterResiduals);
94 // compare the track parameters
95 bool areParamCompatible = areCompatible(track1.param(), track2.param(), precision);
96 bool areCovCompatible = areCompatible(track1.param().getCovariances(), track2.param().getCovariances(), precision);
97 if (!areParamCompatible || !areCovCompatible) {
98 ++nDifferences;
99 }
100 if (printAll || (printDiff && !areParamCompatible)) {
101 printResiduals(track1.param(), track2.param());
102 }
103 if (printAll || (printDiff && !areCovCompatible)) {
104 printCovResiduals(track1.param().getCovariances(), track2.param().getCovariances());
105 }
106 fillTrackResiduals(track1.param(), track2.param(), trackResidualsAtFirstCluster);
107 break;
108 }
109 }
110 }
111
112 // then print the missing tracks
113 for (const auto& track1 : tracks1) {
114 if (!track1.hasMatchFound()) {
115 if (printDiff) {
116 std::cout << "did not find a track in file 2 matching: " << track1 << "\n";
117 }
118 ++nDifferences;
119 }
120 }
121
122 // and finally print the additional tracks
123 for (const auto& track2 : tracks2) {
124 if (!track2.hasMatchFound()) {
125 if (printDiff) {
126 std::cout << "did not find a track in file 1 matching: " << track2 << "\n";
127 }
128 ++nDifferences;
129 }
130 }
131
132 return nDifferences;
133}
134
135bool areCompatible(const TrackParam& param1, const TrackParam& param2, double precision)
136{
138 return (abs(param2.getNonBendingCoor() - param1.getNonBendingCoor()) <= precision &&
139 abs(param2.getBendingCoor() - param1.getBendingCoor()) <= precision &&
140 abs(param2.getZ() - param1.getZ()) <= precision &&
141 abs(param2.px() - param1.px()) <= precision &&
142 abs(param2.py() - param1.py()) <= precision &&
143 abs(param2.pz() - param1.pz()) <= precision &&
144 param2.getCharge() == param1.getCharge());
145}
146
147bool areCompatible(const TMatrixD& cov1, const TMatrixD& cov2, double precision)
148{
150 if (cov1.NonZeros() == 0 || cov2.NonZeros() == 0) {
151 return true;
152 }
153 TMatrixD diff(cov2, TMatrixD::kMinus, cov1);
154 return (diff <= precision && diff >= -precision);
155}
156
157bool isSelected(const ExtendedTrack& track)
158{
160
161 static const double sigmaPDCA23 = 80.;
162 static const double sigmaPDCA310 = 54.;
163 static const double nSigmaPDCA = 6.;
164 static const double relPRes = 0.0004;
165 static const double slopeRes = 0.0005;
166
167 double thetaAbs = TMath::ATan(track.getRabs() / 505.) * TMath::RadToDeg();
168 if (thetaAbs < 2. || thetaAbs > 10.) {
169 return false;
170 }
171
172 double eta = track.P().Eta();
173 if (eta < -4. || eta > -2.5) {
174 return false;
175 }
176
177 double pUncorr = TMath::Sqrt(track.param().px() * track.param().px() + track.param().py() * track.param().py() + track.param().pz() * track.param().pz());
178 double pDCA = pUncorr * track.getDCA();
179 double sigmaPDCA = (thetaAbs < 3) ? sigmaPDCA23 : sigmaPDCA310;
180 double pTot = track.P().P();
181 double nrp = nSigmaPDCA * relPRes * pTot;
182 double pResEffect = sigmaPDCA / (1. - nrp / (1. + nrp));
183 double slopeResEffect = 535. * slopeRes * pTot;
184 double sigmaPDCAWithRes = TMath::Sqrt(pResEffect * pResEffect + slopeResEffect * slopeResEffect);
185 if (pDCA > nSigmaPDCA * sigmaPDCAWithRes) {
186 return false;
187 }
188
189 return true;
190}
191
192void selectTracks(std::list<ExtendedTrack>& tracks)
193{
195 for (auto itTrack = tracks.begin(); itTrack != tracks.end();) {
196 if (!isSelected(*itTrack)) {
197 itTrack = tracks.erase(itTrack);
198 } else {
199 ++itTrack;
200 }
201 }
202}
203
204} // namespace o2::mch::eval
track parameters for internal use
Definition TrackParam.h:34
Double_t pz() const
Double_t getNonBendingCoor() const
return non bending coordinate (cm)
Definition TrackParam.h:51
Double_t py() const
Double_t getZ() const
return Z coordinate (cm)
Definition TrackParam.h:47
Double_t getBendingCoor() const
return bending coordinate (cm)
Definition TrackParam.h:59
Double_t px() const
Double_t getCharge() const
return the charge (assumed forward motion)
Definition TrackParam.h:71
const TrackParam & param() const
const ROOT::Math::PxPyPzMVector & P() const
GLenum GLint GLint * precision
Definition glcorearb.h:1899
bool areCompatible(const TrackParam &param1, const TrackParam &param2, double precision)
void selectTracks(std::list< ExtendedTrack > &tracks)
int compareEvents(std::list< ExtendedTrack > &tracks1, std::list< ExtendedTrack > &tracks2, double precision, bool printDiff, bool printAll, std::vector< TH1 * > &trackResidualsAtFirstCluster, std::vector< TH1 * > &clusterClusterResiduals)
bool isSelected(const ExtendedTrack &track)
void printResiduals(const TrackParam &param1, const TrackParam &param2)
void fillTrackResiduals(const TrackParam &param1, const TrackParam &param2, std::vector< TH1 * > &histos)
Definition Histos.cxx:161
void fillClusterClusterResiduals(const ExtendedTrack &track1, const ExtendedTrack &track2, std::vector< TH1 * > &histos)
Definition Histos.cxx:179
void printCovResiduals(const TMatrixD &cov1, const TMatrixD &cov2)