GeoModel - GeoModelCore
GeoCutVolAction.cxx
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GeoModelKernel/GeoCutVolAction.h"
6 #include "GeoModelKernel/GeoPhysVol.h"
7 #include "GeoModelKernel/GeoIdentifierTag.h"
8 #include "GeoModelKernel/GeoNameTag.h"
9 #include "GeoModelKernel/GeoTransform.h"
10 #include "GeoModelKernel/GeoShapeShift.h"
11 #include "GeoModelKernel/GeoShapeSubtraction.h"
12 
13 GeoCutVolAction::GeoCutVolAction(const GeoShape& Shape,
14  const GeoTrf::Transform3D& Transform)
15  : GeoVolumeAction (GeoVolumeAction::TOP_DOWN)
16  , m_physVol(0)
17  , m_shape(Shape)
18  , m_transform(Transform)
19  , m_copyStack(new std::stack<GeoPhysVol*>)
20 {
21 }
22 
23 GeoCutVolAction::~GeoCutVolAction()
24 {
25  while(m_copyStack->size()>0)
26  m_copyStack->pop();
27  delete m_copyStack;
28 }
29 
30 void GeoCutVolAction::handleVPhysVol(const GeoVPhysVol *pv)
31 {
32  // Determine path length:
33  // 0 - for the starting PV
34  // 1 - for the first level daughters etc.
35  unsigned int pathLen = this->getState()->getPath()->getLength();
36 
37  // Get Logical Volume details
38  const GeoLogVol* lvOriginal = pv->getLogVol();
39  const std::string& lvNameOriginal = lvOriginal->getName();
40  const GeoMaterial* lvMatOriginal = lvOriginal->getMaterial();
41  const GeoShape* lvShapeOriginal = lvOriginal->getShape();
42 
43  if(pathLen==0)
44  {
45  // We are at the first PV. Create the resulting PV
46  const GeoShape& cutShape = (*lvShapeOriginal).subtract(m_shape << m_transform);
47  GeoLogVol* lvNew = new GeoLogVol(lvNameOriginal,&cutShape,lvMatOriginal);
48 
49  m_physVol = new GeoPhysVol(lvNew);
50 
51  // Save the new PV in the copy stack
52  m_copyStack->push(m_physVol);
53  }
54  else
55  {
56  // determine the parent PV in the copy tree
57  while(m_copyStack->size()>pathLen)
58  m_copyStack->pop();
59  GeoPhysVol* copyParent = m_copyStack->top();
60 
61  // Calculate cut transform to the reference frame of current PV
62  GeoTrf::Transform3D cutTransform = (this->getState()->getAbsoluteTransform()).inverse()*m_transform;
63 
64  // Construct new PV
65  const GeoShape& cutShape = (*lvShapeOriginal).subtract(m_shape << cutTransform);
66  GeoLogVol* lvNew = new GeoLogVol(lvNameOriginal,&cutShape,lvMatOriginal);
67  GeoPhysVol* pvNew = new GeoPhysVol(lvNew);
68 
69  // Get its characteristics (name, id, transform to parent)
70  std::string pvName = this->getState()->getName();
71  if(pvName != "")
72  copyParent->add(new GeoNameTag(pvName));
73 
74  const Query<int> pvId = this->getState()->getId();
75  if(pvId.isValid())
76  copyParent->add(new GeoIdentifierTag(pvId));
77 
78  copyParent->add(new GeoTransform(this->getState()->getTransform()));
79  copyParent->add(pvNew);
80 
81  // Save new PV in the copy stack
82  m_copyStack->push(pvNew);
83  }
84 }
85 
86 GeoPhysVol* GeoCutVolAction::getPV()
87 {
88  return m_physVol;
89 }
A Logical Volume, or agglomeration of shape and material. The logical volume increases the reference ...
Definition: GeoLogVol.h:20
This type of action sees and traverses a simpler tree of positioned volumes. It does not descend into...
This class gives a name to the next physical volume.
Definition: GeoNameTag.h:17
This class gives an integral identifer to the following physical volume.
const GeoLogVol * getLogVol() const
Returns the logical volume.
Definition: GeoVPhysVol.cxx:39
virtual GeoTrf::Transform3D getTransform(const GeoVAlignmentStore *store=nullptr) const override
Gets the total transform, including the alignment correction.
A basic geometrical (Euclidean) transform. Can return a GeoTrf::Transform3D. Reference counted...
Definition: GeoTransform.h:22
A GeoPhysVol is a physical volume for normal recursive access only. This means, normally, that it represents a piece of detector that nobody cares about except for tracing engines like GEANT. More specifically:
Definition: GeoPhysVol.h:31
This class describes a Shape. Shapes will be able to do the following things:
Definition: GeoShape.h:38
This class represents materials. A material is a collection of elements. In addition it has a density...
Definition: GeoMaterial.h:33