VGM Version 5.3
Loading...
Searching...
No Matches
DisplacedSolid.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The RootGM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
12//
13// Class DisplacedSolid
14// ---------------------
15// VGM implementation for Root displaced solid
16//
17// Author: Ivana Hrivnacova; IPN Orsay
18
20
22#include "RootGM/solids/Box.h"
25
26#include "TGeoBBox.h"
27#include "TGeoBoolNode.h"
28#include "TGeoCompositeShape.h"
29#include "TGeoHalfSpace.h"
30#include "TGeoMatrix.h"
31#include "TString.h"
32
33#include <cstdlib>
34
35const std::string RootGM::DisplacedSolid::fgkNameExtension = "_displ";
36
37//_____________________________________________________________________________
39 const std::string& name, VGM::ISolid* solid, TGeoMatrix* displacement)
40 : VGM::ISolid(),
41 VGM::IDisplacedSolid(),
42 BaseVGM::VDisplacedSolid(),
43 fCompositeShape(0),
44 fConstituentSolid(solid)
45{
50
51 // Get solid from the solid map
52 TGeoShape* rootSolid = RootGM::SolidMap::Instance()->GetSolid(solid);
53
54 // Define new name
55 // std::string newName = name + fgkNameExtension; // ??
56 std::string newName = name;
57
58 // Register TGeo matrix
59 displacement->SetName(newName.data());
60 displacement->RegisterYourself();
61
62 TGeoBoolNode* boolNode = new TGeoUnion(rootSolid, rootSolid, displacement, 0);
63
64 fCompositeShape = new TGeoCompositeShape(newName.data(), boolNode);
65
66 RootGM::SolidMap::Instance()->AddSolid(this, fCompositeShape);
67}
68
69//_____________________________________________________________________________
71 : VGM::ISolid(),
72 VGM::IDisplacedSolid(),
73 BaseVGM::VDisplacedSolid(),
74 fCompositeShape(0),
75 fConstituentSolid(0)
76{
79
80 // Give exception if box does not include offset
81 const Double_t* origin = box->GetOrigin();
82 if (!origin) {
83 std::cerr << " RootGM::DisplacedSolid::DisplacedSolid: " << std::endl;
84 std::cerr << " Cannot create displaced solid from a box without offset."
85 << std::endl;
86 std::cerr << " (TGeoBBox name = " << box->GetName() << ")" << std::endl;
87 std::cerr << "*** Error: Aborting execution ***" << std::endl;
88 exit(1);
89 }
90
91 // Define new name
92 std::string newName = std::string(box->GetName()) + fgkNameExtension;
93
94 // Create VGM box for constituent solid not registered in solid map
95 fConstituentSolid = new RootGM::Box(box, false);
96 // RootGM::SolidMap::Instance()->AddSolid(fConstituentSolid, box);
97
98 // Create and register TGeo matrix
99 TGeoMatrix* displacement =
100 new TGeoTranslation(origin[0], origin[1], origin[2]);
101 displacement->SetName(newName.data());
102 displacement->RegisterYourself();
103
104 TGeoBoolNode* boolNode = new TGeoUnion(box, box, displacement, 0);
105
106 fCompositeShape = new TGeoCompositeShape(newName.data(), boolNode);
107
108 RootGM::SolidMap::Instance()->AddSolidInRootMapOnly(this, fCompositeShape);
110}
111
112//_____________________________________________________________________________
114 : VGM::ISolid(),
115 VGM::IDisplacedSolid(),
116 BaseVGM::VDisplacedSolid(),
117 fCompositeShape(0),
118 fConstituentSolid(0)
119{
123
124 // Define new name
125 std::string newName = std::string(halfSpace->GetName()) + fgkNameExtension;
126
127 // Create a big box for constituent solid not registered in solid map
128 double size = 1.0e03; // 100 m
129 // when set 1.0e05 the test fails
130 TGeoBBox* box = new TGeoBBox("bigBox", size, size, size);
131 fConstituentSolid = new RootGM::Box(box, false);
132 RootGM::SolidMap::Instance()->AddSolid(fConstituentSolid, halfSpace);
133
134 // Get half space parameters
135 Double_t* point = halfSpace->GetPoint();
136 Double_t* norm = halfSpace->GetNorm();
137
138 // Rotate box to get the norm of the z+ side (0,0,1)
139 // in the norm direction
140 Double_t mtx[3][3];
141 Double_t from[3];
142 from[0] = 0.;
143 from[1] = 0.;
144 from[2] = 1.0;
145 RootGM::fromToRotation(from, norm, mtx);
146
147 Double_t rot[9];
148 rot[0] = mtx[0][0];
149 rot[1] = mtx[0][1];
150 rot[2] = mtx[0][2];
151 rot[3] = mtx[1][0];
152 rot[4] = mtx[1][1];
153 rot[5] = mtx[1][2];
154 rot[6] = mtx[2][0];
155 rot[7] = mtx[2][1];
156 rot[8] = mtx[2][2];
157 TGeoRotation* rotation = new TGeoRotation();
158 rotation->SetMatrix(rot);
159
160 // Transform the box origin
161 Double_t origin[3];
162 origin[0] = 0;
163 origin[1] = 0;
164 origin[2] = -size;
165 Double_t newOrigin[3];
166 rotation->LocalToMaster(origin, newOrigin);
167 for (Int_t i = 0; i < 3; i++) newOrigin[i] = newOrigin[i] + point[i];
168
169 // Create and register TGeo matrix
170 TGeoMatrix* displacement =
171 new TGeoCombiTrans(newOrigin[0], newOrigin[1], newOrigin[2], rotation);
172 displacement->SetName(newName.data());
173 displacement->RegisterYourself();
174
175 TGeoBoolNode* boolNode = new TGeoUnion(box, box, displacement, 0);
176
177 fCompositeShape = new TGeoCompositeShape(newName.data(), boolNode);
178
179 RootGM::SolidMap::Instance()->AddSolidInRootMapOnly(this, fCompositeShape);
181}
182
183//_____________________________________________________________________________
185 : VGM::ISolid(), VGM::IDisplacedSolid(), BaseVGM::VDisplacedSolid()
186{
188}
189
190//_____________________________________________________________________________
192 : VGM::ISolid(rhs), VGM::IDisplacedSolid(rhs), BaseVGM::VDisplacedSolid(rhs)
193{
195}
196
197//_____________________________________________________________________________
202
203//
204// public methods
205//
206
207//_____________________________________________________________________________
209{
210 // Returns the Displaced solid name
211 // ---
212
213 return fCompositeShape->GetName();
214}
215
216//_____________________________________________________________________________
218{
219 // Returns the second constituent solid.
220 // ---
221
222 return fConstituentSolid;
223}
224
225//_____________________________________________________________________________
227{
228 // Returns the solid displacemnt transformation
229 // in the frame of the first (left) solid.
230 // ---
231
232 TGeoBoolNode* boolNode = fCompositeShape->GetBoolNode();
233
234 TGeoMatrix* matrixB = boolNode->GetLeftMatrix();
235 TGeoHMatrix transformB(*matrixB);
236
237 return Transform(transformB);
238}
VGM implementation for Root box solid.
Definition Box.h:32
VGM implementation for Root displaced solid.
virtual std::string Name() const
Return the name of this solid.
virtual VGM::ISolid * ConstituentSolid() const
Return the constituent solid.
virtual VGM::Transform Displacement() const
Return the 3D displacement of the constituent solid.
TGeoShape * GetSolid(VGM::ISolid *iSolid) const
Definition SolidMap.cxx:86
void AddSolidInRootMapOnly(VGM::ISolid *, TGeoShape *)
Definition SolidMap.cxx:68
void AddSolid(VGM::ISolid *, TGeoShape *)
Definition SolidMap.cxx:59
void AddSolidInVGMMapOnly(VGM::ISolid *, TGeoShape *)
Definition SolidMap.cxx:77
static SolidMap * Instance()
Definition SolidMap.cxx:28
The VGM interface to solids.
Definition ISolid.h:58
BaseVGM utilities.
Definition utilities.h:23
void fromToRotation(double from[3], double to[3], double mtx[3][3])
VGM::Transform Transform(const TGeoMatrix &matrix)
Definition transform.cxx:37
VGM interfaces.
Definition VMedium.h:28
std::vector< double > Transform
Definition Transform.h:40