Newer
Older
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
namespace {
struct Loader { Loader() { gSystem->Load("libDD4hepCore"); } } _load;
}
using namespace DD4hep::Geometry;
void printPos(const char* com, const Position& p) {
printf("%-24s: %7.3f %7.3f %7.3f\n",com,p.x(),p.y(),p.z());
}
void printCoord(const Position& global, const Position& local) {
printPos("Global",global);
printPos("Local",local);
}
void local_to_world(const char* com,const DetElement de, const Position& pos,const Position& loc) {
Position glob;
printf("Local to World: Transformation '%s'(%7.3f, %7.3f, %7.3f)->world (Should be: (%7.3f, %7.3f, %7.3f) :\n",
com, loc.x(),loc.y(),loc.z(),
loc.x()+pos.x(),loc.y()+pos.y(),loc.z()+pos.z() );
de.localToWorld(loc,glob);
printCoord(glob,loc);
}
void world_to_local(const char* com,const DetElement de, const Position& pos,const Position& glob) {
Position loc;
printf("World to Local: Transformation '%s'(%7.3f, %7.3f, %7.3f)->world (Should be: (%7.3f, %7.3f, %7.3f) :\n",
com, glob.x(),glob.y(),glob.z(),
glob.x()-pos.x(),glob.y()-pos.y(),glob.z()-pos.z() );
de.worldToLocal(glob,loc);
printCoord(glob,loc);
}
int BoxTrafos() {
string xml = "file:";
xml += gSystem->Getenv("DD4hepINSTALL");
xml += "/examples/ClientTests/compact/BoxTrafos.xml";
const char* argv[] = {xml.c_str(), "BUILD_DEFAULT", 0};
gSystem->Load("libDD4hepCore");
LCDD& lcdd = LCDD::getInstance();
lcdd.apply("DD4hepCompactLoader",2,(char**)argv);
lcdd.apply("DD4hepGeometryDisplay",0,0);
DetElement de = lcdd.detector("B3");
PlacedVolume pv = de.placement();
Volume vol = pv.volume();
Solid solid = vol.solid();
TGeoBBox* box = (TGeoBBox*)(solid.ptr());
Position glob,loc, pos(-10,30,10);
printf("\n++++ local->world:\n\n");
loc = Position(-pos.x(),-pos.y(),-pos.z());
local_to_world("origine",de,pos,loc);
loc = Position();
local_to_world("center",de,pos,loc);
loc = Position(box->GetDX(),box->GetDY(),box->GetDZ());
local_to_world("top edge",de,pos,loc);
loc = Position(box->GetDX(),box->GetDY(),-box->GetDZ());
local_to_world("top edge",de,pos,loc);
loc = Position(-box->GetDX(),box->GetDY(),box->GetDZ());
local_to_world("top edge",de,pos,loc);
loc = Position(-box->GetDX(),box->GetDY(),-box->GetDZ());
local_to_world("top edge",de,pos,loc);
loc = Position(box->GetDX(),-box->GetDY(),box->GetDZ());
local_to_world("bottom edge",de,pos,loc);
loc = Position(box->GetDX(),-box->GetDY(),-box->GetDZ());
local_to_world("bottom edge",de,pos,loc);
loc = Position(-box->GetDX(),-box->GetDY(),box->GetDZ());
local_to_world("bottom edge",de,pos,loc);
loc = Position(-box->GetDX(),-box->GetDY(),-box->GetDZ());
local_to_world("bottom edge",de,pos,loc);
printf("\n++++ world->local:\n\n");
glob = Position(0,0,0);
world_to_local("world center",de,pos,glob);
glob = Position(pos.x(),pos.y(),pos.z());
world_to_local("position",de,pos,glob);
glob = Position( box->GetDX()+pos.x(), box->GetDY()+pos.y(), box->GetDZ()+pos.z());
world_to_local("top edge",de,pos,glob);
glob = Position( box->GetDX()+pos.x(), box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
world_to_local("top edge",de,pos,glob);
glob = Position(-box->GetDX()+pos.x(), box->GetDY()+pos.y(), box->GetDZ()+pos.z());
world_to_local("top edge",de,pos,glob);
glob = Position(-box->GetDX()+pos.x(), box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
world_to_local("top edge",de,pos,glob);
glob = Position( box->GetDX()+pos.x(), -box->GetDY()+pos.y(), box->GetDZ()+pos.z());
world_to_local("bottom edge",de,pos,glob);
glob = Position( box->GetDX()+pos.x(), -box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
world_to_local("bottom edge",de,pos,glob);
glob = Position(-box->GetDX()+pos.x(), -box->GetDY()+pos.y(), box->GetDZ()+pos.z());
world_to_local("bottom edge",de,pos,glob);
glob = Position(-box->GetDX()+pos.x(), -box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
world_to_local("bottom edge",de,pos,glob);
return 1;
}