-
Notifications
You must be signed in to change notification settings - Fork 0
/
cstr.C
60 lines (58 loc) · 2.82 KB
/
cstr.C
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
#include "TGeoMatrix.h"
void PrintMat(const char* name, const double mt[4][4])
{
printf("\nD/D%s\n",name);
for (int i=0;i<4;i++) {
for (int j=0;j<4;j++) printf("%+e ",mt[i][j]); printf("\n");
}
}
void cstr(TGeoHMatrix &matRD, double jac[6][6])
{
// If the transformation R brings the vector from "local" frame to "master" frame as V=R*v
// then application of the small LOCAL correction tau to vector v is equivalent to
// aplication of correction TAU in MASTER framce V' = R*tau*v = TAU*R*v
// with TAU = R*tau*R^-1
// Constraining the LOCAL modifications of child volumes to have 0 total movement in their parent
// frame is equivalent to request that sum of all TAU matrices is unity matrix, or TAU-I = 0.
//
// This routine calculates derivatives of the TAU-I matrix over local corrections x,y,z, psi,tht,phi
// defining matrix TAU. In small corrections approximation the constraint is equivalent to
// Sum_over_child_volumes{ [dTAU/dParam]_ij * deltaParam } = 0
// for all elements ij of derivative matrices. Since only 6 out of 16 matrix params are independent,
// we request the constraint only for [01],[02],[13],[30],[31],[32]
//
TGeoHMatrix matRI = matRD.Inverse();
const int ij[6][2] = {{0,1},{0,2},{1,2},{3,0},{3,1},{3,2}};
//
const double *rd=matRD.GetRotationMatrix(),*ri=matRI.GetRotationMatrix();
const double *td=matRD.GetTranslation(), *ti=matRI.GetTranslation();
//
double dDPar[6][4][4] = {
// dDX[4][4]
{{0,0,0,0},{0,0,0,0},{0,0,0,0},{rd[0],rd[3],rd[6],0}},
// dDY[4][4]
{{0,0,0,0},{0,0,0,0},{0,0,0,0},{rd[1],rd[4],rd[7],0}},
// dDZ[4][4]
{{0,0,0,0},{0,0,0,0},{0,0,0,0},{rd[2],rd[5],rd[8],0}},
// dDPSI[4][4]
{{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