22 #include <mach/mach_time.h>
24 #ifndef CLOCK_REALTIME
25 #define CLOCK_REALTIME 0
27 #ifndef CLOCK_MONOTONIC
28 #define CLOCK_MONOTONIC 0
30 inline int clock_gettime(
int ,
struct timespec* t) {
31 mach_timebase_info_data_t timebase;
32 mach_timebase_info(&timebase);
34 time = mach_absolute_time();
36 ((double) time * (
double) timebase.numer) / ((
double) timebase.denom);
38 ((double) time * (
double) timebase.numer) / ((
double) timebase.denom * 1e9);
40 t->tv_nsec = nseconds;
53 #define NOF_SIGMAS_SQ NOF_SIGMAS* NOF_SIGMAS
138 , tx((lP.
x - rP.
x) / deltaZ)
139 , dtxSq((lP.dx - rP.dx) * (lP.dx - rP.dx) / (deltaZ * deltaZ))
140 , ty((lP.
y - rP.
y) / deltaZ)
141 , dtySq((lP.dy - rP.dy) * (lP.dy - rP.dy) / (deltaZ * deltaZ))
190 for (
int i = 0;
i < nybs; ++
i)
252 new unsigned char[noftb * sizeof(
LxTbTYXBin)]))
254 for (
int i = 0;
i < noftb; ++
i)
309 for (
int i = 0;
i < 4; ++
i) {
311 new unsigned char[noftb *
sizeof(
LxTbTYXBin)]);
313 for (
int j = 0; j < noftb; ++j) {
322 for (
int i = 0;
i < 4; ++
i)
323 delete[]
reinterpret_cast<unsigned char*
>(
tyxBinsArr[
i]);
327 for (
int i = 0;
i < 4; ++
i) {
358 scaltype deltaZSq = deltaZ * deltaZ;
361 param.
coord += prevParam.
tg * deltaZ;
364 param.
C11 += prevParam.
C12 * deltaZ + prevParam.
C21 * deltaZ
365 + prevParam.
C22 * deltaZSq + Q.
Q11;
366 param.
C12 += prevParam.
C22 * deltaZ + Q.
Q12;
367 param.
C21 += prevParam.
C22 * deltaZ + Q.
Q21;
374 param.
coord += Kcoord * dzeta;
375 param.
tg += Ktg * dzeta;
376 param.
C21 -= param.
C11 * Ktg;
377 param.
C22 -= param.
C12 * Ktg;
378 param.
C11 *= 1.0 - Kcoord;
379 param.
C12 *= 1.0 - Kcoord;
380 chi2 += dzeta * S * dzeta;
467 void Insert(
const std::pair<timetype, timetype>&
v) {
484 for (
int i = minInd;
i <= maxInd; ++
i) {
485 for (std::list<std::pair<timetype, timetype>>::const_iterator j =
489 const std::pair<timetype, timetype>& p = *j;
491 if (
fabs(
v.first - p.first)
565 std::pair<int, int>* nofSpatBins,
572 ,
trdStation(nofTrdXBins, nofTrdYBins, nofTimeBins)
604 nofSpatBins[
i].
first, nofSpatBins[
i].second, nofTimeBins);
612 delete[]
reinterpret_cast<unsigned char*
>(&
stations[
i]);
618 for (
int i = 0;
true; ++
i) {
677 q0XSq * L * L / 3, q0XSq * L / 2, q0XSq * L / 2, q0XSq};
679 q0YSq * L * L / 3, q0YSq * L / 2, q0YSq * L / 2, q0YSq};
715 for (
int i = 1;
i < n; ++
i) {
718 for (
int j = 0; j <
i; ++j)
732 / ((Ls2[n - 1] + Ls1[n]) * (Ls2[n - 1] + Ls1[n]));
735 / ((Ls2[n - 1] + Ls1[n]) * (Ls2[n - 1] + Ls1[n]));
771 std::list<LxTbBinnedPoint*>& results) {
821 for (
int lTind = lTindMin; lTind <= lTindMax; ++lTind) {
824 for (
int lYind = lYindMin; lYind <= lYindMax; ++lYind) {
827 for (
int lXind = lXindMin; lXind <= lXindMax; ++lXind) {
830 for (std::list<LxTbBinnedPoint>::iterator
i = lXBin.
points.begin();
835 if (point.
x >
x - wX && point.
x <
x + wX && point.
y >
y - wY
836 && point.
y <
y + wY && point.
t > t - wT && point.
t < t + wT)
837 results.push_back(&point);
847 clock_gettime(CLOCK_REALTIME, &ts);
848 long beginTime = ts.tv_sec * 1000000000 + ts.tv_nsec;
852 int nofXBins = lastStation.
nofXBins;
853 int nofYBins = lastStation.
nofYBins;
962 int lastXBin = lStation.
nofXBins - 1;
963 int lastYBin = lStation.
nofYBins - 1;
968 if (!rTyxBin.
use)
continue;
970 for (
int k = 0; k < rNofYBins; ++k) {
973 if (!rYxBin.
use)
continue;
975 for (
int l = 0; l < rNofXBins; ++l) {
978 if (!rXBin.
use)
continue;
980 for (std::list<LxTbBinnedPoint>::iterator
m = rXBin.
points.begin();
985 if (!rPoint.
use)
continue;
991 scaltype trajLen =
sqrt(1 + tx * tx + ty * ty) * deltaZ;
1004 if (pX + wX < minX || pX - wX > maxX || pY + wY < minY
1005 || pY - wY > maxY || pT + wT < minT || pT - wT >
maxT)
1022 int lYindMin = (pY - wY - minY) / binSizeY;
1026 else if (lYindMin > lastYBin)
1027 lYindMin = lastYBin;
1029 int lYindMax = (pY + wY - minY) / binSizeY;
1033 else if (lYindMax > lastYBin)
1034 lYindMax = lastYBin;
1036 int lXindMin = (pX - wX - minX) / binSizeX;
1040 else if (lXindMin > lastXBin)
1041 lXindMin = lastXBin;
1043 int lXindMax = (pX + wX - minX) / binSizeX;
1047 else if (lXindMax > lastXBin)
1048 lXindMax = lastXBin;
1050 for (
int lTind = lTindMin; lTind <= lTindMax; ++lTind) {
1053 for (
int lYind = lYindMin; lYind <= lYindMax; ++lYind) {
1056 for (
int lXind = lXindMin; lXind <= lXindMax; ++lXind) {
1059 for (std::list<LxTbBinnedPoint>::iterator n =
1069 scaltype deltaXSq = deltaX * deltaX;
1071 scaltype deltaYSq = deltaY * deltaY;
1073 timetype deltaTSq = deltaT * deltaT;
1075 if (deltaXSq < wX_prec_sq && deltaYSq < wY_prec_sq
1076 && deltaTSq < wT * wT) {
1083 deltaXSq / xDiv + deltaYSq / yDiv
1085 / (rPoint.
dt * rPoint.
dt
1086 + lPoint.
dt * lPoint.
dt)));
1090 if (lXBin.
use) lYxBin.
use =
true;
1093 if (lYxBin.
use) lTyxBin.
use =
true;
1107 if (!rTyxBin.
use)
continue;
1109 for (
int j = 0; j < nofYBins; ++j) {
1112 if (!rYxBin.
use)
continue;
1114 for (
int k = 0; k < nofXBins; ++k) {
1117 if (!rXBin.
use)
continue;
1119 for (std::list<LxTbBinnedPoint>::iterator l = rXBin.
points.begin();
1123 std::list<ChainImpl> chains;
1126 rPoint.
x / lastStation.
z,
1127 rPoint.
dx * rPoint.
dx,
1132 rPoint.
y / lastStation.
z,
1133 rPoint.
dy * rPoint.
dy,
1144 for (std::list<ChainImpl>::const_iterator
m = chains.begin();
1149 if (0 == bestChain || chain.
chi2 < chi2) {
1155 if (0 != bestChain) {
1160 if (trackBinInd < 0)
1169 for (std::list<ChainImpl>::iterator
m = chains.begin();
1183 scaltype beforeLastZ = beforeLastStation.
z;
1193 scaltype trdDeltaZ10Sq = trdDeltaZ10 * trdDeltaZ10;
1195 scaltype trdDeltaZ21Sq = trdDeltaZ21 * trdDeltaZ21;
1197 scaltype trdDeltaZ31Sq = trdDeltaZ31 * trdDeltaZ31;
1202 for (std::list<Chain*>::iterator j = recoTracksBin.begin();
1203 j != recoTracksBin.end();
1208 scaltype tx = (lPoint.
x - lPointL.
x) / (lastZ - beforeLastZ);
1209 scaltype ty = (lPoint.
y - lPointL.
y) / (lastZ - beforeLastZ);
1210 scaltype trdPx0 = lPoint.
x + tx * deltaZsTrd[0];
1211 scaltype trdPy0 = lPoint.
y + ty * deltaZsTrd[0];
1212 scaltype trajLen0 =
sqrt(1 + tx * tx + ty * ty) * deltaZsTrd[0];
1214 lPoint.
t + 1.e9 * trajLen0 / c;
1220 std::list<LxTbBinnedPoint*> results0;
1221 FindNeighbours(trdPx0, wX0, trdPy0, wY0, trdPt0, wT0, 0, results0);
1223 scaltype trdPx1 = lPoint.
x + tx * deltaZsTrd[1];
1224 scaltype trdPy1 = lPoint.
y + ty * deltaZsTrd[1];
1225 scaltype trajLen1 =
sqrt(1 + tx * tx + ty * ty) * deltaZsTrd[1];
1227 lPoint.
t + 1.e9 * trajLen1 / c;
1233 std::list<LxTbBinnedPoint*> results1;
1234 FindNeighbours(trdPx1, wX1, trdPy1, wY1, trdPt1, wT1, 1, results1);
1236 for (std::list<LxTbBinnedPoint*>::const_iterator k = results0.begin();
1237 k != results0.end();
1241 for (std::list<LxTbBinnedPoint*>::const_iterator l =
1243 l != results1.end();
1246 scaltype trdTx = (trdPoint1.
x - trdPoint0.
x) / trdDeltaZ10;
1247 scaltype trdTy = (trdPoint1.
y - trdPoint0.
y) / trdDeltaZ10;
1249 (trdPoint0.
dx * trdPoint0.
dx + trdPoint1.
dx * trdPoint1.
dx)
1252 (trdPoint0.
dy * trdPoint0.
dy + trdPoint1.
dy * trdPoint1.
dy)
1255 scaltype trdPx2 = trdPoint1.
x + trdTx * trdDeltaZ21;
1256 scaltype trdPy2 = trdPoint1.
y + trdTy * trdDeltaZ21;
1258 sqrt(1 + trdTx * trdTx + trdTx * trdTx) * trdDeltaZ21;
1260 trdPoint1.
t + 1.e9 * trajLen2 / c;
1263 *
sqrt(0.0878375 * 0.0878375 + trdDtxSq * trdDeltaZ21Sq
1264 + trdPoint1.
dx * trdPoint1.
dx);
1267 *
sqrt(0.0837875 * 0.0837875 + trdDtySq * trdDeltaZ21Sq
1268 + trdPoint1.
dy * trdPoint1.
dy);
1270 std::list<LxTbBinnedPoint*> results2;
1272 trdPx2, wX2, trdPy2, wY2, trdPt2, wT2, 2, results2);
1274 if (results2.empty())
continue;
1276 scaltype trdPx3 = trdPoint1.
x + trdTx * trdDeltaZ31;
1277 scaltype trdPy3 = trdPoint1.
y + trdTy * trdDeltaZ31;
1279 sqrt(1 + trdTx * trdTx + trdTx * trdTx) * trdDeltaZ31;
1281 trdPoint1.
t + 1.e9 * trajLen3 / c;
1283 *
sqrt(0.22725 * 0.22725 + trdDtxSq * trdDeltaZ31Sq
1284 + trdPoint1.
dx * trdPoint1.
dx);
1287 *
sqrt(0.211375 * 0.211375 + trdDtySq * trdDeltaZ31Sq
1288 + trdPoint1.
dy * trdPoint1.
dy);
1290 std::list<LxTbBinnedPoint*> results3;
1292 trdPx3, wX3, trdPy3, wY3, trdPt3, wT3, 3, results3);
1294 if (!results3.empty()) {
1308 clock_gettime(CLOCK_REALTIME, &ts);
1309 long endTime = ts.tv_sec * 1000000000 + ts.tv_nsec;
1320 std::list<ChainImpl>& chains) {
1321 points[stationIndex] = rPoint;
1323 if (0 == stationIndex) {
1325 chains.push_back(chain);
1329 for (std::list<LxTbBinnedRay>::const_iterator
i =
1345 KFAddPoint(kfParams, kfParamsPrev,
m, V, stationIndex - 1);
1351 std::list<Chain*>& borderTracks,
1353 bool handleBorder) {
1354 std::list<Chain*>::const_iterator it =
1355 handleBorder ? borderTracks.begin() : recoTracksBin.begin();
1356 std::list<Chain*>::const_iterator endIt =
1357 handleBorder ? borderTracks.end() : recoTracksBin.end();
1359 for (; it != endIt; ++it) {
1367 borderTracks.push_back(track);
1372 std::list<Chain*>::const_iterator it2 =
1373 handleBorder ? recoTracksBin.begin() : it;
1374 std::list<Chain*>::const_iterator endIt2 = recoTracksBin.end();
1376 if (!handleBorder) ++it2;
1378 for (; it2 != endIt2; ++it2) {
1379 Chain* track2 = *it2;
1395 std::pair<timetype, timetype> pairTime((point->
t + point2->
t) / 2,
1396 sqrt(dtSq + dt2Sq) / 2);
1399 if (trackSign * track2Sign < 0) {
1416 if (trackSign * track2Sign < 0) {
1427 if (trackSign * track2Sign < 0) {
1441 std::list<Chain*> borderTracks;
1445 borderTracks.clear();