31#include "TGeoBoolNode.h"
32#include "TGeoCompositeShape.h"
33#include "TGeoManager.h"
34#include "TGeoMatrix.h"
36#include "TGeoVolume.h"
38bool RootGM::Placement::fgIncludeAssembliesInNames =
true;
39char RootGM::Placement::fgNameSeparator =
'%';
40char RootGM::Placement::fgNamePrefix =
'&';
48 bool includeAssembliesInNames)
53 fgIncludeAssembliesInNames = includeAssembliesInNames;
62 return fgIncludeAssembliesInNames;
70 fgNameSeparator = nameSeparator;
78 fgNamePrefix = namePrefix;
86 return fgNameSeparator;
105 BaseVGM::VPlacement(volume, motherVolume),
108 fVGMMatrix(transformation),
124 fGeoNode = gGeoManager->GetTopNode();
131 TGeoMatrix* totalMatrix = transformation;
135 totalMatrix = ComposeMatrix(volume, motherVolume, transformation);
136 totalMatrix->SetName(name.data());
137 totalMatrix->RegisterYourself();
143 TGeoVolume* geoMotherVolume =
147 geoMotherVolume->AddNode(geoVolume, copyNo, totalMatrix);
150 fGeoNode = geoMotherVolume->GetNode(geoMotherVolume->GetNdaughters() - 1);
162 BaseVGM::VPlacement(volume, motherVolume),
179 TGeoVolume* geoMotherVolume =
189 geoMotherVolume->GetShape()->GetAxisRange(iAxis, xlo, xhi);
190 Double_t start = xlo + offset;
193 geoMotherVolume->Divide(name.data(), iAxis, nofItems, start, width);
196 fGeoNode = geoMotherVolume->GetNode(geoMotherVolume->GetNdaughters() - 1);
206 BaseVGM::VPlacement(volume, motherVolume),
214 if (volume) fName = volume->
Name();
218 fVGMMatrix = node->GetMatrix();
222 node->GetOverlaps(novlp);
224 std::cerr <<
"*** Warning: node with overlaps ***" << std::endl
225 <<
"*** Overlaps may not be supported in exported geometry!!! ***"
227 <<
" Volume: " << volume->
Name()
228 <<
" in mother: " << motherVolume->
Name()
229 <<
" (TGeoNode name: " << node->GetName() <<
")" << std::endl;
238 TGeoNode* node, std::vector<const TGeoNode*> assemblyNodes)
240 BaseVGM::VPlacement(volume, motherVolume),
244 fAssemblyNodes(assemblyNodes)
248 if (volume) fName = volume->
Name();
252 fVGMMatrix = node->GetMatrix();
266 :
VGM::IPlacement(rhs),
BaseVGM::VPlacement(rhs)
282TGeoMatrix* RootGM::Placement::ComposeMatrix(
VGM::IVolume* volume,
283 VGM::IVolume* motherVolume, TGeoMatrix* transformation)
const
287 TGeoHMatrix motherTransform;
292 TGeoHMatrix displacement(
294 motherTransform = motherTransform * displacement;
299 TGeoHMatrix solidTransform;
304 TGeoHMatrix displacement(
306 solidTransform = solidTransform * displacement;
311 TGeoHMatrix totalTransform =
312 motherTransform.Inverse() * TGeoHMatrix(*transformation) * solidTransform;
314 return new TGeoHMatrix(totalTransform);
328 const TGeoPatternFinder* finder = fGeoNode->GetMotherVolume()->GetFinder();
344 if (fgIncludeAssembliesInNames) {
345 for (
unsigned i = 0; i < fAssemblyNodes.size(); i++) {
346 if (i == 0) name += fgNamePrefix;
347 name += fAssemblyNodes[i]->GetName();
348 name += fgNameSeparator;
351 name += fName.c_str();
360 return fGeoNode->GetNumber();
368 TGeoHMatrix transform3D;
369 if (fGeoNode->GetVolume()->GetShape()->IsComposite()) {
370 TGeoCompositeShape* composite =
371 (TGeoCompositeShape*)fGeoNode->GetVolume()->GetShape();
372 TGeoMatrix* leftMatrix = composite->GetBoolNode()->GetLeftMatrix();
374 TGeoHMatrix t1(*leftMatrix);
375 TGeoHMatrix t2(*(fGeoNode->GetMatrix()));
377 transform3D = t2 * t1;
383 TGeoShape* shapeA = composite->GetBoolNode()->GetLeftShape();
385 while (shapeA->IsComposite()) {
386 TGeoBoolNode* boolNodeAC = ((TGeoCompositeShape*)shapeA)->GetBoolNode();
388 TGeoShape* shapeAC = boolNodeAC->GetLeftShape();
391 TGeoMatrix* matrixAC = boolNodeAC->GetLeftMatrix();
392 TGeoHMatrix transformAC(*matrixAC);
394 transform3D = transform3D * transformAC;
400 transform3D = fGeoNode->GetMatrix();
407 transform3D = TGeoHMatrix(*fVGMMatrix);
411 for (
unsigned i = fAssemblyNodes.size(); i > 0; i--) {
412 TGeoMatrix* matrixAN = fAssemblyNodes[i - 1]->GetMatrix();
413 TGeoHMatrix transformAN(*matrixAN);
414 transform3D = transformAN * transform3D;
419 transform3D.SetBit(TGeoMatrix::kGeoRegistered,
false);
426 double& width,
double& offset,
double& halfGap)
const
429 const TGeoPatternFinder* finder = fGeoNode->GetMotherVolume()->GetFinder();
430 if (!finder)
return false;
434 nofItems = finder->GetNdiv();
435 Double_t start = finder->GetStart();
437 fGeoNode->GetMotherVolume()->GetShape()->GetAxisRange(
439 offset = start - xlo;
440 width = finder->GetStep();
453 std::vector<VGM::Transform>& ,
454 std::vector<VGM::IVolume*>& )
const
459 std::cout <<
"Please implement RootGM::Placement::ParameterisedPlacementData "
460 "if you need to use it!"
static PlacementMap * Instance()
void AddPlacement(VGM::IPlacement *, TGeoNode *)
VGM implementation for Root positions of volumes.
static bool GetIncludeAssembliesInNames()
static void SetNamePrefix(char namePrefix)
virtual VGM::Transform Transformation() const
Return the 3D transformation (if simple placement)
static void SetNameSeparator(char nameSeparator)
static char GetNamePrefix()
virtual VGM::PlacementType Type() const
Return the type of this placement.
static void SetIncludeAssembliesInNames(bool includeAssembliesInNames)
virtual std::string Name() const
Return the name of this placement.
static char GetNameSeparator()
virtual bool ParameterisedPlacementData(std::vector< VGM::Transform > &transforms, std::vector< VGM::IVolume * > &volumes) const
Fill the parameterised placement data if relevant and return true; return false if not parameterised ...
virtual int CopyNo() const
Return the copy number of this placement.
virtual bool MultiplePlacementData(VGM::Axis &axis, int &nofItems, double &width, double &offset, double &halfGap) const
Fill the multiple placement data if relevant and return true; return false if not multiple placement.
static double AxisUnit(VGM::Axis axis)
Return Root unit for the given axis in VGM units.
static VolumeMap * Instance()
TGeoVolume * GetVolume(VGM::IVolume *iVolume) const
VGM implementation for Root volume.
The VGM interface to displaced solids.
virtual ISolid * ConstituentSolid() const =0
Return the constituent solid.
virtual Transform Displacement() const =0
Return the 3D displacement of the constituent solid.
The VGM interface to solids.
virtual SolidType Type() const =0
Return the type of this solid.
The VGM interface to volumes.
virtual ISolid * Solid() const =0
Return the associated solid.
virtual std::string Name() const =0
Return the name of this volume.
TGeoMatrix * CreateTransform(const VGM::Transform &transform)
VGM::Axis Axis(const TGeoPatternFinder *finder)
VGM::Transform Transform(const TGeoMatrix &matrix)
std::vector< double > Transform