Belle II Software  release-08-01-10
CLAWSCreator.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/claws/geometry/CLAWSCreator.h>
10 #include <beast/claws/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 claws {
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 CLAWSCreator::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  std::vector<double> ri = params.getArray("r", {0});
64  int phase = 0;
65  if (ri.size() > 1) phase = 1;
66 
67  //const double r = params.getLength("r", 0) / Unit::mm * CLHEP::mm;
68  const double top = params.getLength("top", 0) / Unit::mm * CLHEP::mm;
69  const double u = params.getLength("u", 0) / Unit::mm * CLHEP::mm;
70  const bool active = params.getBool("active", false);
71 
72  G4Material* mat = m_topMaterial;
73  if (!material.empty()) {
74  mat = geometry::Materials::get(material);
75  }
76  G4VSolid* shape{nullptr};
77  double height{0};
78  if (type == "box") {
79  const double length = params.getLength("length") / Unit::mm * CLHEP::mm;
80  const double width = params.getLength("width") / Unit::mm * CLHEP::mm;
81  height = params.getLength("height") / Unit::mm * CLHEP::mm;
82  shape = new G4Box(name, width / 2, height / 2, length / 2);
83  } else if (type == "tube") {
84  const double length = params.getLength("length") / Unit::mm * CLHEP::mm;
85  height = params.getLength("diameter") / Unit::mm * CLHEP::mm;
86  shape = new G4Tubs(name, 0, height / 2, length / 2, 0, 2 * M_PI);
87  }
88  G4LogicalVolume* volume = new G4LogicalVolume(shape, mat, name);
89  if (active) {
90  volume->SetSensitiveDetector(m_sensitive);
91  if (m_stepLength) {
92  volume->SetUserLimits(m_stepLength);
93  }
94  }
95  for (const GearDir& child : params.getNodes("shape")) {
96  createShape(name, child, volume, height / 2, true);
97  }
98 
99  int copyNo = 1;
100 
101  if (!phase) {
102  double center = ri[0] / Unit::mm * CLHEP::mm + roffset - height / 2 - top;
103  //center *=CLHEP::mm / Unit::mm;
104  for (double phi : params.getArray("phi", {M_PI / 2})) {
105  for (double z : params.getArray("z", {0})) {
106  z *= CLHEP::mm / Unit::mm;
107  G4Transform3D transform = G4RotateZ3D(phi - M_PI / 2) * G4Translate3D(u, center, z);
108  new G4PVPlacement(transform, volume, name, parent, false, copyNo++, check);
109  }
110  }
111  } else {
112  int i = 0;
113  std::vector<double> alpha = params.getArray("alpha", {0});
114  for (double z : params.getArray("z", {0})) {
115  double center = ri[i] / Unit::mm * CLHEP::mm + roffset - height / 2 - top;
116  // center *= CLHEP::mm / Unit::mm;
117  z *= CLHEP::mm / Unit::mm;
118  for (double phi : params.getArray("phi", {M_PI / 2})) {
119  G4Transform3D transform = G4RotateZ3D(phi - M_PI / 2) * G4Translate3D(u, center, z) * G4RotateY3D(alpha[i]);
120  new G4PVPlacement(transform, volume, name, parent, false, copyNo++, check);
121  }
122  i++;
123  }
124 
125  }
126  }
127 
128 
129 
130  void CLAWSCreator::create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes /* type */)
131  {
132  m_topMaterial = topVolume.GetMaterial();
133  double stepLength = content.getLength("stepLength", 0) / Unit::mm * CLHEP::mm;
134  if (stepLength > 0) {
135  if (m_stepLength) delete m_stepLength;
136  m_stepLength = new G4UserLimits(stepLength);
137  }
138  for (auto shape : content.getNodes("shape")) {
139  createShape("", shape, &topVolume, 0, false);
140  }
141  }
142  } // claws namespace
144 } // 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: CLAWSCreator.cc:49
virtual ~CLAWSCreator()
Destructor.
Definition: CLAWSCreator.cc:43
virtual void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type)
Creation of the detector geometry from Gearbox (XML).
CLAWSCreator(Simulation::SensitiveDetectorBase *sensitive=nullptr)
Constructor.
Definition: CLAWSCreator.cc:36
G4UserLimits * m_stepLength
pointer to the G4Userlimits to set for sensitive volumes (if any)
Definition: CLAWSCreator.h:66
Simulation::SensitiveDetectorBase * m_sensitive
pointer to the sensitive detector implementation
Definition: CLAWSCreator.h:62
G4Material * m_topMaterial
pointer to the material in the top volume to use as default
Definition: CLAWSCreator.h:64
Sensitive Detector implementation of the CLAWS detector.
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:63
geometry::CreatorFactory< CLAWSCreator > CLAWSFactory("CLAWSCreator")
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.