forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheckPropagation.C
More file actions
219 lines (187 loc) · 6.42 KB
/
Copy pathcheckPropagation.C
File metadata and controls
219 lines (187 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "Riostream.h"
#include "TFile.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TH1F.h"
#include "GPUCommonConstants.h"
#include "GPUO2Interface.h"
#include "GPUTPCGMPhysicalTrackModel.h"
#endif
using namespace o2::gpu;
const double kTwoPi = TMath::TwoPi(); // 2.*kPi;
const double kSectorDAngle = kTwoPi / 18.;
const double kSectorAngleOffset = kSectorDAngle / 2;
int32_t GetSector(double GlobalPhi)
{
double phi = GlobalPhi;
// std::cout<<" GetSector: phi = "<<phi<<std::endl;
if (phi >= kTwoPi) {
phi -= kTwoPi;
}
if (phi < 0) {
phi += kTwoPi;
}
return (int32_t)(phi / kSectorDAngle);
}
int32_t GetDSector(double LocalPhi) { return GetSector(LocalPhi + kSectorAngleOffset); }
double GetSectorAngle(int32_t iSector) { return kSectorAngleOffset + iSector * kSectorDAngle; }
int32_t RecalculateSector(GPUTPCGMPhysicalTrackModel& t, AliExternalTrackParam& t0, int32_t& iSector)
{
double phi = atan2(t.GetY(), t.GetX());
// std::cout<<" recalculate: phi = "<<phi<<std::endl;
int32_t dSector = GetDSector(phi);
if (dSector == 0) {
return 0; // nothing to do
}
// std::cout<<" dSector = "<<dSector<<std::endl;
double dAlpha = dSector * kSectorDAngle;
iSector += dSector;
if (iSector >= 18) {
iSector -= 18;
}
// rotate track on angle dAlpha
t.Rotate(dAlpha);
t0.Rotate(GetSectorAngle(iSector));
return 1;
}
int32_t checkPropagation()
{
// gSystem->Load("libAliHLTTPC");
TH1F* hDiff[3] = {0, 0, 0};
for (int32_t i = 0; i < 3; i++) {
char* s = i == 0 ? "X" : (i == 1 ? "Y" : "Z");
char name[1024], title[1024];
snprintf(name, 1024, "hDiff%s", s);
snprintf(title, 1024, "Propagation Difference in %s", s);
hDiff[i] = new TH1F(name, title, 1000, -20., 20.);
hDiff[i]->GetXaxis()->SetTitle("Propagation difference [um]");
}
AliMagF* fld = new AliMagF("Fit", "Fit", 1., 1., AliMagF::k5kG);
GPUTPCGMPolynomialField field;
GPUTPCGMPolynomialFieldManager fieldCr;
fieldCr.GetPolynomialField(field);
GPUTPCGMPropagator prop;
prop.SetPolynomialField(&field);
const int32_t nTracks = 1000;
for (int32_t itr = 0; itr < nTracks; itr++) {
std::cout << "Track " << itr << ":" << std::endl;
double dphi = kTwoPi / nTracks;
double phi = kSectorAngleOffset + dphi * itr;
double eta = gRandom->Uniform(-1.5, 1.5);
double theta = 2 * TMath::ATan(1. / TMath::Exp(eta));
double lambda = theta - TMath::Pi() / 2;
// double theta = gRandom->Uniform(-60,60)*TMath::Pi()/180.;
double pt = .1 * std::pow(10, gRandom->Uniform(0, 2.2));
double q = 1.;
int32_t iSector = GetSector(phi);
phi = phi - GetSectorAngle(iSector);
// std::cout<<"phi = "<<phi<<std::endl;
double x0 = cos(phi);
double y0 = sin(phi);
double z0 = tan(lambda);
double px = pt * x0;
double py = pt * y0;
double pz = pt * z0;
GPUTPCGMPhysicalTrackModel t;
t.Set(x0, y0, z0, px, py, pz, q);
AliExternalTrackParam t0;
{
double alpha = GetSectorAngle(iSector);
double p[5] = {t.GetY(), t.GetZ(), t.GetSinPhi(), t.GetDzDs(), t.GetQPt()};
double cv[15];
for (int32_t i = 0; i < 15; i++) {
cv[i] = 0;
}
t0 = AliExternalTrackParam(x0, alpha, p, cv);
}
if (RecalculateSector(t, t0, iSector) != 0) {
std::cout << "Initial sector wrong!!!" << std::endl;
// exit(0);
}
AliHLTTPCGeometry geo;
for (int32_t iRow = 0; iRow < geo.GetNRows(); iRow++) {
// if( iRow>=50 ) break; //SG!!!
float xRow = geo.Row2X(iRow);
// transport to row
int32_t err = 0;
for (int32_t itry = 0; itry < 1; itry++) {
double alpha = GetSectorAngle(iSector);
float B[3];
prop.GetBxByBz(alpha, t.GetX(), t.GetY(), t.GetZ(), B);
// B[0]=0;
// B[1]=0;
float dLp = 0;
err = t.PropagateToXBxByBz(xRow, B[0], B[1], B[2], dLp);
double cs = TMath::Cos(alpha);
double sn = TMath::Sin(alpha);
const double kCLight = o2::gpu::gpu_common_constants::kCLight;
double b[3] = {(B[0] * cs - B[1] * sn) / kCLight, (B[0] * sn + B[1] * cs) / kCLight, B[2] / kCLight};
err = err & !t0.PropagateToBxByBz(xRow, b);
// err = err & !t0.PropagateTo( xRow, b[2] );
if (err) {
std::cout << "Can not propagate to x = " << xRow << std::endl;
t.Print();
break;
}
if (fabsf(t.GetZ()) >= GPUTPCGeometry::TPCLength()) {
std::cout << "Can not propagate to x = " << xRow << ": Z outside the volume" << std::endl;
t.Print();
err = -1;
break;
}
// rotate track coordinate system to current sector
int32_t isNewSector = RecalculateSector(t, t0, iSector);
if (!isNewSector) {
break;
} else {
std::cout << "track " << itr << ": new sector " << iSector << " at row " << iRow << std::endl;
}
}
if (err) {
break;
}
// std::cout<<" track "<<itr<<": Sector "<<iSector<<" row "<<iRow<<" params :"<<std::endl;
// t.Print();
// track at row iRow, sector iSector
t.UpdateValues();
double dx = 1.e4 * (t.GetX() - t0.GetX());
double dy = 1.e4 * (t.GetY() - t0.GetY());
double dz = 1.e4 * (t.GetZ() - t0.GetZ());
hDiff[0]->Fill(dx);
hDiff[1]->Fill(dy);
hDiff[2]->Fill(dz);
// cout<<" x "<<xRow<<" dx "<<dx<<" dy "<<dy<<" dz "<<dz<<endl;
} // iRow
} // itr
// finish
TFile* tout = new TFile("propagate.root", "RECREATE");
TCanvas* c = new TCanvas("PropagatorErrors", "Propagator Errors", 0, 0, 700, 700. * 2. / 3.);
c->Divide(3);
int32_t ipad = 1;
for (int32_t i = 0; i < 3; i++) {
c->cd(ipad++);
if (tout) {
hDiff[i]->Write();
}
gPad->SetLogy();
hDiff[i]->Draw();
}
c->Print("propagatorErrors.pdf");
delete c;
if (tout) {
tout->Close();
delete tout;
}
return 0;
}