Belle II Software  release-08-01-10
FANGSCreator.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <beast/fangs/geometry/FANGSCreator.h>
10 #include <beast/fangs/simulation/SensitiveDetector.h>
11 
12 #include <geometry/Materials.h>
13 #include <geometry/CreatorFactory.h>
14 #include <framework/gearbox/GearDir.h>
15 #include <framework/gearbox/Unit.h>
16 
17 #include <G4LogicalVolume.hh>
18 #include <G4PVPlacement.hh>
19 #include <G4Box.hh>
20 #include <G4Tubs.hh>
21 #include <G4UserLimits.hh>
22 
23 namespace Belle2 {
30  namespace fangs {
31 
32  // Register the creator
35 
37  {
38  /*if (!m_sensitive) {
39  m_sensitive = new SensitiveDetector();
40  }*/
41  }
42 
44  {
45  delete m_sensitive;
46  delete m_stepLength;
47  }
48 
49  void FANGSCreator::createShape(const std::string& prefix, const GearDir& params, G4LogicalVolume* parent, double roffset,
50  bool check)
51  {
52 
53  if (!m_sensitive) {
55  }
56 
57  std::string name = params.getString("@name");
58  if (!prefix.empty()) {
59  name = prefix + "." + name;
60  }
61  const std::string type = params.getString("@type");
62  const std::string material = params.getString("material", "");
63  const double r = params.getLength("r", 0) / Unit::mm * CLHEP::mm;
64  const double top = params.getLength("top", 0) / Unit::mm * CLHEP::mm;
65  const double u = params.getLength("u", 0) / Unit::mm * CLHEP::mm;
66  const bool active = params.getBool("active", false);
67 
68  G4Material* mat = m_topMaterial;
69  if (!material.empty()) {
70  mat = geometry::Materials::get(material);
71  }
72  G4VSolid* shape{nullptr};
73  double height{0};
74  if (type == "box") {
75  const double length = params.getLength("length") / Unit::mm * CLHEP::mm;
76  const double width = params.getLength("width") / Unit::mm * CLHEP::mm;
77  height = params.getLength("height") / Unit::mm * CLHEP::mm;
78  shape = new G4Box(name, width / 2, height / 2, length / 2);
79  } else if (type == "tube") {
80  const double length = params.getLength("length") / Unit::mm * CLHEP::mm;
81  height = params.getLength("diameter") / Unit::mm * CLHEP::mm;
82  shape = new G4Tubs(name, 0, height / 2, length / 2, 0, 2 * M_PI);
83  }
84  G4LogicalVolume* volume = new G4LogicalVolume(shape, mat, name);
85  if (active) {
86  volume->SetSensitiveDetector(m_sensitive);
87  if (m_stepLength) {
88  volume->SetUserLimits(m_stepLength);
89  }
90  }
91  for (const GearDir& child : params.getNodes("shape")) {
92  createShape(name, child, volume, height / 2, true);
93  }
94 
95  int copyNo = 1;
96  const double center = r + roffset - height / 2 - top;
97  for (double phi : params.getArray("phi", {M_PI / 2})) {
98  for (double z : params.getArray("z", {0})) {
99  z *= CLHEP::mm / Unit::mm;
100  G4Transform3D transform = G4RotateZ3D(phi - M_PI / 2) * G4Translate3D(u, center, z);
101  new G4PVPlacement(transform, volume, name, parent, false, copyNo++, check);
102  }
103  }
104  }
105 
106  void FANGSCreator::create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes /* type */)
107  {
108  m_topMaterial = topVolume.GetMaterial();
109  double stepLength = content.getLength("stepLength", 0) / Unit::mm * CLHEP::mm;
110  if (stepLength > 0) {
111  if (m_stepLength) delete m_stepLength;
112  m_stepLength = new G4UserLimits(stepLength);
113  }
114  for (auto shape : content.getNodes("shape")) {
115  createShape("", shape, &topVolume, 0, false);
116  }
117  }
118  } // fangs namespace
120 } // Belle2 namespace
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
Base class for all Sensitive Detectors to create hits during simulation.
static const double mm
[millimeters]
Definition: Unit.h:70
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:49
FANGSCreator(Simulation::SensitiveDetectorBase *sensitive=nullptr)
Constructor.
Definition: FANGSCreator.cc:36
virtual void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type)
Creation of the detector geometry from Gearbox (XML).
virtual ~FANGSCreator()
Destructor.
Definition: FANGSCreator.cc:43
G4UserLimits * m_stepLength
pointer to the G4Userlimits to set for sensitive volumes (if any)
Definition: FANGSCreator.h:65
Simulation::SensitiveDetectorBase * m_sensitive
pointer to the sensitive detector implementation
Definition: FANGSCreator.h:61
G4Material * m_topMaterial
pointer to the material in the top volume to use as default
Definition: FANGSCreator.h:63
Sensitive Detector implementation of the FANGS detector.
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:63
geometry::CreatorFactory< FANGSCreator > FANGSFactory("FANGSCreator")
Creator creates the CLAW geometry.
GeometryTypes
Flag indiciating the type of geometry to be used.
Abstract base class for different kinds of events.
Very simple class to provide an easy way to register creators with the CreatorManager.