CbmRoot
Loading...
Searching...
No Matches
CaUvConverter.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov [committer] */
4
5#include "CaUvConverter.h"
6
7#include <Logger.h>
8
9#include <cmath>
10#include <iostream>
11
12using namespace cbm::ca;
13
14//----------------------------------------------------------------------------------------------------------------------
15//
16void CaUvConverter::SetFromUV(double phiU, double phiV)
17{
18 fcosU = cos(phiU);
19 fsinU = sin(phiU);
20 fcosV = cos(phiV);
21 fsinV = sin(phiV);
22
23 double det = fcosU * fsinV - fsinU * fcosV;
24 if (fabs(det) < 1.e-2) {
25 LOG(error) << "CaUvConverter: U & V coordinates are too close: " << phiU << " " << phiV;
26 phiV = phiU + 10. / 180. * M_PI;
27 fcosV = cos(phiV);
28 fsinV = sin(phiV);
29 det = fcosU * fsinV - fsinU * fcosV;
30 }
31 fcosX = fsinV / det;
32 fsinX = -fsinU / det;
33 fcosY = -fcosV / det;
34 fsinY = fcosU / det;
35}
36
37//----------------------------------------------------------------------------------------------------------------------
38//
39void CaUvConverter::SetFromXYCovMatrix(double phiU, double dx2, double dxy, double dy2)
40{
41 // take U coordinate from fPhiU
42 double cosU = cos(phiU);
43 double sinU = sin(phiU);
44 double du2 = cosU * cosU * dx2 + 2 * sinU * cosU * dxy + sinU * sinU * dy2;
45
46 // take V coordinate from the hit covariance matrix, making V uncorrelated with U
47
48 // rotate X,Y coordinates on angle fPhiU (X,Y) -> (U,W)
49
50 //double du2 = cosU * cosU * dx2 + 2. * sinU * cosU * dxy + sinU * sinU * dy2;
51 double duw = sinU * cosU * (dy2 - dx2) + (cosU * cosU - sinU * sinU) * dxy;
52 //double dw2 = cosU * cosU * dy2 - 2. * sinU * cosU * dxy + sinU * sinU * dx2;
53
54 // find an angle in rotaded coordinates, that has 0 covariance with U
55 double phiV = phiU + atan2(du2, -duw);
56
57 SetFromUV(phiU, phiV);
58
59 // check that u/v covariance is 0.
60 auto [tmp1, duv, dv2] = ConvertCovMatrixXYtoUV(dx2, dxy, dy2);
61
62 if (fabs(duv) > 1.e-8) {
63 LOG(error) << "can not define V coordinate from XY covariance matrix";
64 }
65
66 //LOG(info) << " u " << phiU / M_PI * 180. << "v " << phiV / M_PI * 180. << " du " << sqrt(du2) << " dv " << sqrt(dv2)
67 // << " duv " << duv;
68}
friend fvec cos(const fvec &a)
friend fvec sin(const fvec &a)
void SetFromXYCovMatrix(double phiU, double dx2, double dxy, double dy2)
construct from U angle and XY covariance matrix
double fcosU
U coordinate in XY.
double fcosY
Y coordinate in UV.
std::tuple< double, double, double > ConvertCovMatrixXYtoUV(double dx2, double dxy, double dy2) const
Conversion function (dx2, dxy, dy2) -> (du2, duv, dv2)
double fcosV
V coordinate in XY.
double fcosX
X coordinate in UV.
void SetFromUV(double phiU, double phiV)
construct from U,V angles