Belle II Software development
AWESOMEGeometryCreator.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/* Own header. */
10#include <online_book/awesome/geometry/AWESOMEGeometryCreator.h>
11
12/* Belle2 headers. */
13#include <framework/gearbox/Unit.h>
14#include <framework/logging/Logger.h>
15#include <geometry/CreatorFactory.h>
16#include <geometry/Materials.h>
17#include <geometry/utilities.h>
18
20#include <G4Box.hh>
21#include <G4PVPlacement.hh>
22#include <G4Transform3D.hh>
23#include <G4UserLimits.hh>
24
25using namespace Belle2;
26using namespace Belle2::AWESOME;
27
29geometry::CreatorFactory<AWESOMEGeometryCreator> AWESOMEFactory("AWESOMECreator");
30
32 m_sensitiveDetector{nullptr}
33{
35}
36
38{
41}
42
43void AWESOMEGeometryCreator::create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes)
44{
45 /* Let's get the stepsize parameter with a default value of 5 µm. */
46 double stepSize = content.getLength("stepSize", 5 * Unit::um);
47 /* Now get the array. Notice that the default framework unit is cm,
48 * so the values will be automatically converted. */
49 B2INFO("Contents of bar:");
50 for (double value : content.getArray("bar")) {
51 B2INFO(LogVar("Value", value));
52 }
53 /* Let's loop over all the Active nodes. */
54 for (const GearDir& activeParams : content.getNodes("Active")) {
55 /* Lets create a Box with dimensions taken from the parameters.
56 * WARNING: Geant4 is in mm so you have to convert the parameters. */
57 G4Box* activeShape = new G4Box("ActiveBox",
58 activeParams.getLength("width") / Unit::mm / 2.0,
59 activeParams.getLength("length") / Unit::mm / 2.0,
60 activeParams.getLength("height") / Unit::mm / 2.0
61 );
62 std::string material = activeParams.getString("Material");
63 G4LogicalVolume* active = new G4LogicalVolume(activeShape, geometry::Materials::get(material),
64 "ActiveVolume", 0, m_sensitiveDetector);
65 /* setColor is an utility function which allows to easily set the color for visualization. */
66 geometry::setColor(*active, "#006699");
67 /* Le's limit the Geant4 stepsize inside the volume. */
68 active->SetUserLimits(new G4UserLimits(stepSize));
69 /* And finally place the volume in the world one. */
70 new G4PVPlacement(G4Translate3D(0, 0, activeParams.getLength("z") / Unit::mm),
71 active, "ActivePlacement", &topVolume, false, 1);
72 }
73}
void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes)
Create the AWESOME detector geometry in the world volume.
AWESOMESensitiveDetector * m_sensitiveDetector
The AWESOME sensitive detector.
virtual ~AWESOMEGeometryCreator()
Default destructor.
Sensitive Detector implementation of the AWESOME detector.
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
static const double mm
[millimeters]
Definition: Unit.h:70
static const double um
[micrometers]
Definition: Unit.h:71
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:63
Class to store variables with their name which were sent to the logging service.
void setColor(G4LogicalVolume &volume, const std::string &color)
Set the color of a logical volume.
Definition: utilities.cc:100
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.