Belle II Software  release-05-01-25
FANGSCreator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2015 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter, Igal Jaegle *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <beast/fangs/geometry/FANGSCreator.h>
12 #include <beast/fangs/simulation/SensitiveDetector.h>
13 
14 #include <geometry/Materials.h>
15 #include <geometry/CreatorFactory.h>
16 #include <framework/gearbox/GearDir.h>
17 #include <framework/gearbox/Unit.h>
18 
19 #include <G4LogicalVolume.hh>
20 #include <G4PVPlacement.hh>
21 #include <G4Box.hh>
22 #include <G4Tubs.hh>
23 #include <G4UserLimits.hh>
24 
25 namespace Belle2 {
32  namespace fangs {
33 
34  // Register the creator
36  geometry::CreatorFactory<FANGSCreator> FANGSFactory("FANGSCreator");
37 
38  FANGSCreator::FANGSCreator(Simulation::SensitiveDetectorBase* sensitive): m_sensitive(sensitive)
39  {
40  if (!m_sensitive) {
42  }
43  }
44 
45  FANGSCreator::~FANGSCreator()
46  {
47  delete m_sensitive;
48  delete m_stepLength;
49  }
50 
51  void FANGSCreator::createShape(const std::string& prefix, const GearDir& params, G4LogicalVolume* parent, double roffset,
52  bool check)
53  {
54  std::string name = params.getString("@name");
55  if (!prefix.empty()) {
56  name = prefix + "." + name;
57  }
58  const std::string type = params.getString("@type");
59  const std::string material = params.getString("material", "");
60  const double r = params.getLength("r", 0) / Unit::mm * CLHEP::mm;
61  const double top = params.getLength("top", 0) / Unit::mm * CLHEP::mm;
62  const double u = params.getLength("u", 0) / Unit::mm * CLHEP::mm;
63  const bool active = params.getBool("active", false);
64 
65  G4Material* mat = m_topMaterial;
66  if (!material.empty()) {
67  mat = geometry::Materials::get(material);
68  }
69  G4VSolid* shape{nullptr};
70  double height{0};
71  if (type == "box") {
72  const double length = params.getLength("length") / Unit::mm * CLHEP::mm;
73  const double width = params.getLength("width") / Unit::mm * CLHEP::mm;
74  height = params.getLength("height") / Unit::mm * CLHEP::mm;
75  shape = new G4Box(name, width / 2, height / 2, length / 2);
76  } else if (type == "tube") {
77  const double length = params.getLength("length") / Unit::mm * CLHEP::mm;
78  height = params.getLength("diameter") / Unit::mm * CLHEP::mm;
79  shape = new G4Tubs(name, 0, height / 2, length / 2, 0, 2 * M_PI);
80  }
81  G4LogicalVolume* volume = new G4LogicalVolume(shape, mat, name);
82  if (active) {
83  volume->SetSensitiveDetector(m_sensitive);
84  if (m_stepLength) {
85  volume->SetUserLimits(m_stepLength);
86  }
87  }
88  for (const GearDir& child : params.getNodes("shape")) {
89  createShape(name, child, volume, height / 2, true);
90  }
91 
92  int copyNo = 1;
93  const double center = r + roffset - height / 2 - top;
94  for (double phi : params.getArray("phi", {M_PI / 2})) {
95  for (double z : params.getArray("z", {0})) {
96  z *= CLHEP::mm / Unit::mm;
97  G4Transform3D transform = G4RotateZ3D(phi - M_PI / 2) * G4Translate3D(u, center, z);
98  new G4PVPlacement(transform, volume, name, parent, false, copyNo++, check);
99  }
100  }
101  }
102 
103  void FANGSCreator::create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes /* type */)
104  {
105  m_topMaterial = topVolume.GetMaterial();
106  double stepLength = content.getLength("stepLength", 0) / Unit::mm * CLHEP::mm;
107  if (stepLength > 0) {
108  if (m_stepLength) delete m_stepLength;
109  m_stepLength = new G4UserLimits(stepLength);
110  }
111  for (auto shape : content.getNodes("shape")) {
112  createShape("", shape, &topVolume, 0, false);
113  }
114  }
115  } // fangs namespace
117 } // Belle2 namespace
Belle2::fangs::FANGSFactory
geometry::CreatorFactory< FANGSCreator > FANGSFactory("FANGSCreator")
Creator creates the CLAW geometry.
Belle2::fangs::FANGSCreator::create
virtual void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type)
Function to actually create the geometry, has to be overridden by derived classes.
Definition: FANGSCreator.cc:111
Belle2::geometry::Materials::get
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:65
Belle2::fangs::FANGSCreator::m_topMaterial
G4Material * m_topMaterial
pointer to the material in the top volume to use as default
Definition: FANGSCreator.h:57
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::fangs::FANGSCreator::m_stepLength
G4UserLimits * m_stepLength
pointer to the G4Userlimits to set for sensitive volumes (if any)
Definition: FANGSCreator.h:59
Belle2::Unit::mm
static const double mm
[millimeters]
Definition: Unit.h:80
Belle2::PXD::SensitiveDetector
VXD::SensitiveDetector< PXDSimHit, PXDTrueHit > SensitiveDetector
The PXD Sensitive Detector class.
Definition: SensitiveDetector.h:36
Belle2::fangs::FANGSCreator::createShape
void createShape(const std::string &prefix, const GearDir &params, G4LogicalVolume *parent, double roffset, bool check)
create a shape (box or cylinder) from XML description and place all child shapes in it by recursively...
Definition: FANGSCreator.cc:59
Belle2::fangs::FANGSCreator::FANGSCreator
FANGSCreator(Simulation::SensitiveDetectorBase *sensitive=nullptr)
Constructor.
Definition: FANGSCreator.cc:46
Belle2::geometry::GeometryTypes
GeometryTypes
Flag indiciating the type of geometry to be used.
Definition: GeometryManager.h:39
Belle2::fangs::FANGSCreator::m_sensitive
Simulation::SensitiveDetectorBase * m_sensitive
pointer to the sensitive detector implementation
Definition: FANGSCreator.h:55