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