DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4PlacementParameterisation.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Volumes.h>
16 #include <DD4hep/Printout.h>
17 #include <DDG4/Geant4Helpers.h>
19 
20 // Geant4 include files
21 #include <G4Transform3D.hh>
22 
25  : G4VPVParameterisation(), m_placement(pv), m_params(*pv.data()->params)
26 {
27  G4Transform3D tr;
28  auto& dim = m_dimensions;
30  m_start.translation = m_start.delta.getTranslation();
31 
32  g4Transform(m_params.trafo1D.first, tr);
33  dim.emplace_back(Dimension(tr, m_params.trafo1D.second));
34 
35  m_have_rotation = false;
36  m_have_rotation |= !dim.back().delta.getRotation().isIdentity();
37  m_num_cells = m_params.trafo1D.second;
38  if ( m_params.trafo2D.second > 0 ) {
39  g4Transform(m_params.trafo2D.first, tr);
40  dim.emplace_back(Dimension(tr, m_params.trafo2D.second));
41  m_have_rotation |= !dim.back().delta.getRotation().isIdentity();
42  m_num_cells *= m_params.trafo2D.second;
43  }
44  if ( m_params.trafo3D.second > 0 ) {
45  g4Transform(m_params.trafo3D.first, tr);
46  dim.emplace_back(Dimension(tr, m_params.trafo3D.second));
47  m_have_rotation |= !dim.back().delta.getRotation().isIdentity();
48  m_num_cells *= m_params.trafo3D.second;
49  }
50  if ( m_have_rotation ) {
51  auto callback = std::bind(&Geant4PlacementParameterisation::operator(),
52  this, std::placeholders::_1);
53  if ( dim.size() == 1 )
55  dim[0].delta, dim[0].count, callback);
56  else if ( dim.size() == 2 )
58  dim[0].delta, dim[0].count,
59  dim[1].delta, dim[1].count, callback);
60  else if ( dim.size() == 3 )
62  dim[0].delta, dim[0].count,
63  dim[1].delta, dim[1].count,
64  dim[2].delta, dim[2].count, callback);
65  }
66 }
67 
70  return m_num_cells;
71 }
72 
74 void dd4hep::sim::Geant4PlacementParameterisation::operator()(const G4Transform3D& transform) {
75  this->m_translations.emplace_back(transform.getTranslation());
76  if ( this->m_have_rotation ) {
77  G4RotationMatrix rot = transform.inverse().getRotation();
78  this->m_rotations.emplace_back(rot);
79  }
80 }
81 
83 void dd4hep::sim::Geant4PlacementParameterisation::ComputeTransformation(const G4int copy, G4VPhysicalVolume *pv) const {
84  const auto& dim = m_dimensions;
85  std::size_t nd = dim.size();
86  if ( !m_have_rotation ) {
87  G4ThreeVector tra = m_start.translation;
88  if ( nd >= 1 ) {
89  std::size_t d1 = 0;
90  if (nd == 1) d1 = copy;
91  else if (nd >= 2) d1 = copy%dim[1].count;
92  tra = tra + (dim[0].translation * d1);
93  }
94  if ( nd >= 2 ) {
95  std::size_t d2 = 0;
96  if (nd == 2) d2 = copy / dim[0].count;
97  else if (nd >= 3 ) d2 = copy%dim[2].count / dim[0].count;
98  tra = tra + (dim[1].translation * d2);
99  }
100  if ( nd >= 3 ) {
101  std::size_t d3 = 0;
102  if ( nd == 3 ) d3 = copy / (dim[0].count*dim[1].count);
103  tra = tra + (dim[2].translation * d3);
104  }
105  pv->SetTranslation(tra);
106  return;
107  }
108  G4RotationMatrix& rot = m_rotations.at(copy);
109  pv->SetTranslation(m_translations.at(copy));
110  pv->SetRotation(&rot);
111 }
dd4hep::sim::Geant4PlacementParameterisation::m_params
const Parameters & m_params
Setup parameters: Reference to the DD4hep placement parameters.
Definition: Geant4PlacementParameterisation.h:72
dd4hep::sim::Geant4PlacementParameterisation::Geant4PlacementParameterisation
Geant4PlacementParameterisation(PlacedVolume pv)
Initializing constructor.
Definition: Geant4PlacementParameterisation.cpp:24
Volumes.h
dd4hep::PlacedVolumeExtension::Parameterisation::trafo3D
Dimension trafo3D
Reference to the parameterised transformation for dimension 3.
Definition: Volumes.h:257
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:163
dd4hep::PlacedVolumeExtension::Parameterisation::trafo2D
Dimension trafo2D
Reference to the parameterised transformation for dimension 2.
Definition: Volumes.h:255
dd4hep::sim::Geant4PlacementParameterisation::Dimension::translation
G4ThreeVector translation
Definition: Geant4PlacementParameterisation.h:45
dd4hep::sim::Geant4PlacementParameterisation::Dimension
Helper structure to cache dimension variabled from setup parameters.
Definition: Geant4PlacementParameterisation.h:43
dd4hep::sim::g4Transform
void g4Transform(const double *translation, const double *rotation, G4Transform3D &transform)
These conversions automatically apply the conversion from CM to MM!
Definition: Geant4Helpers.cpp:91
Geant4PlacementParameterisation.h
dd4hep::sim::Geant4PlacementParameterisation::m_dimensions
Dimensions m_dimensions
Setup parameters: Dimensional parameter setup.
Definition: Geant4PlacementParameterisation.h:76
Geant4Helpers.h
dd4hep::PlacedVolumeExtension::Parameterisation::trafo1D
Dimension trafo1D
Reference to the parameterised transformation for dimension 1.
Definition: Volumes.h:253
dd4hep::sim::Geant4PlacementParameterisation::m_start
Dimension m_start
Setup parameters: Initial parameterisation position.
Definition: Geant4PlacementParameterisation.h:74
dd4hep::sim::Geant4PlacementParameterisation::m_num_cells
size_t m_num_cells
Total number of parameterized cells.
Definition: Geant4PlacementParameterisation.h:81
dd4hep::sim::generate_placements
G4Transform3D generate_placements(const G4Transform3D &start, const G4Transform3D &delta, std::size_t count, const std::function< void(const G4Transform3D &delta)> &callback)
Generate parameterised placements in 1 dimension according to transformation delta.
Definition: Geant4Helpers.cpp:157
dd4hep::sim::Geant4PlacementParameterisation::count
std::size_t count() const
Access number of replicas.
Definition: Geant4PlacementParameterisation.cpp:69
dd4hep::sim::Geant4PlacementParameterisation::Dimension::delta
G4Transform3D delta
Definition: Geant4PlacementParameterisation.h:44
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::sim::Geant4PlacementParameterisation::operator()
void operator()(const G4Transform3D &transform)
Callback to store resulting rotation.
Definition: Geant4PlacementParameterisation.cpp:74
dd4hep::sim::Geant4PlacementParameterisation::ComputeTransformation
virtual void ComputeTransformation(const G4int copyNo, G4VPhysicalVolume *vol) const override
G4VPVParameterisation overload: Compute copy transformation.
Definition: Geant4PlacementParameterisation.cpp:83
dd4hep::PlacedVolumeExtension::Parameterisation::start
Transform3D start
Reference to the starting point of the parameterisation.
Definition: Volumes.h:251
Printout.h
dd4hep::sim::Geant4PlacementParameterisation::m_have_rotation
bool m_have_rotation
Optimization flag for simple parameteristions.
Definition: Geant4PlacementParameterisation.h:83