Belle II Software  release-05-01-25
GeoVXDServiceCreator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter, Benjamin Schwenker *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <vxd/geometry/GeoVXDServiceCreator.h>
12 #include <vxd/geometry/GeoVXDComponents.h>
13 #include <geometry/CreatorFactory.h>
14 #include <geometry/Materials.h>
15 #include <simulation/background/BkgSensitiveDetector.h>
16 #include <framework/gearbox/GearDir.h>
17 #include <framework/logging/Logger.h>
18 #include <G4Transform3D.hh>
19 #include <G4LogicalVolume.hh>
20 #include <G4PVPlacement.hh>
21 #include <G4Tubs.hh>
22 #include <G4Box.hh>
23 #include <map>
24 
25 namespace Belle2 {
30  using namespace geometry;
31  namespace VXD {
32 
34  geometry::CreatorFactory<GeoVXDServiceCreator> GeoVXDServiceFactory("VXDServiceCreator");
35 
37  VXDServiceGeometryPar GeoVXDServiceCreator::createConfiguration(const GearDir& content)
38  {
39  VXDServiceGeometryPar vxdServiceGeometryPar(content.getBool("RecordBackground", false));
40 
41  GearDir content2(content, "DockBoxes");
42 
43  // Read parameters to creates boxes
44  for (const GearDir& boxtype : content2.getNodes("BoxType")) {
45  VXDBoxTypesPar boxtypePar(
46  boxtype.getString("@name"),
47  boxtype.getString("material"),
48  boxtype.getInt("@identifier", 0),
49  boxtype.getLength("width"),
50  boxtype.getLength("length"),
51  boxtype.getLength("height")
52  );
53  vxdServiceGeometryPar.getBoxTypes().push_back(boxtypePar);
54  }
55 
56  // Read paramater to place boxes
57  for (const GearDir& position : content2.getNodes("Position")) {
58  VXDBoxPositionsPar positionPar(
59  position.getString("@name"),
60  position.getLength("minZ"),
61  position.getLength("maxZ"),
62  position.getLength("minR"),
63  position.getLength("maxR"),
64  position.getInt("divisions")
65  );
66  for (const GearDir& slot : position.getNodes("slots")) {
67  VXDSlotsPar slotsPar(slot.getString("@type"));
68  for (const double number : slot.getArray("")) {
69  slotsPar.getSlotNumbers().push_back(number);
70  }
71  positionPar.getSlots().push_back(slotsPar);
72  }
73  vxdServiceGeometryPar.getPositions().push_back(positionPar);
74  }
75 
76  return vxdServiceGeometryPar;
77  }
78 
79  void GeoVXDServiceCreator::createGeometry(const VXDServiceGeometryPar& parameters, G4LogicalVolume& topVolume, GeometryTypes)
80  {
81  m_defaultMaterial = topVolume.GetMaterial();
82  bool active = parameters.getRecordBackground();
83 
84  // Create the Boxes
85  std::map<std::string, VXDGeoComponent> boxes;
86 
87  for (const VXDBoxTypesPar& boxtype : parameters.getBoxTypes()) {
88  VXDGeoComponent box(
89  boxtype.getMaterial(), "",
90  boxtype.getWidth() / 2.0 / Unit::mm, 0,
91  boxtype.getLength() / 2.0 / Unit::mm,
92  boxtype.getHeight() / 2.0 / Unit::mm);
93  const std::string name = boxtype.getName();
94  G4VSolid* shape_box = new G4Box(name, box.getHeight(), box.getWidth(), box.getLength());
95  box.setVolume(new G4LogicalVolume(shape_box, Materials::get(box.getMaterial()), name));
96  B2DEBUG(50, "Created " << name << " DockBox with a mass of " << (box.getVolume()->GetMass(true) / CLHEP::kg) << "kg");
97  if (active) {
98  int identifier = boxtype.getIdentifier();
99  B2DEBUG(50, "Creating BkgSensitiveDetector for DockBox " << name << " with identifier " << identifier);
100  BkgSensitiveDetector* sensitive = new BkgSensitiveDetector(name.c_str(), identifier);
101  box.getVolume()->SetSensitiveDetector(sensitive);
102  }
103  boxes[name] = box;
104  }
105 
106  // Now place the Boxes
107  for (const VXDBoxPositionsPar& position : parameters.getPositions()) {
108  const double minZ = position.getMinZ() / Unit::mm;
109  const double maxZ = position.getMaxZ() / Unit::mm;
110  const double minR = position.getMinR() / Unit::mm;
111  const double maxR = position.getMaxR() / Unit::mm;
112  const int divisions = position.getDivisions();
113  const std::string name = "VXD.DockBoxes." + position.getName();
114 
115  //Boxes are aligned to the side closer to the IP so we need the sign in
116  //which to shift
117  const int signZ = minZ < 0 ? -1 : +1;
118 
119  G4VSolid* shape_envelope = new G4Tubs(name, minR, maxR, (maxZ - minZ) / 2.0, 0, 2 * M_PI);
120  G4LogicalVolume* envelope = new G4LogicalVolume(shape_envelope, m_defaultMaterial, name);
121  new G4PVPlacement(G4TranslateZ3D((minZ + maxZ) / 2.0), envelope, name, &topVolume, false, 1);
122  //We have divisions slots with always to slots joining at phi=0
123  //As such, the center phi of one slot is 2pi/divisions*(i+0.5);
124  //We start numbering with i=0 as the slot with the smallest phi>0
125  for (const VXDSlotsPar& slot : position.getSlots()) {
126  const std::string type = slot.getType();
127  const VXDGeoComponent& box = boxes[type];
128  if (!box.getVolume()) B2FATAL("Unknown DockBox type: " << type);
129  for (double number : slot.getSlotNumbers()) {
130  const double angle = (2 * M_PI / divisions) * (number + 0.5);
131  //Position boxes as close to beamline as envelope allows
132  const double r = minR + box.getHeight();
133  //Shift the box as close to the IP as the envelope allows
134  const double z = -signZ * ((maxZ - minZ) / 2.0 - box.getLength());
135  const G4Transform3D placement = G4RotateZ3D(angle) * G4Translate3D(r, 0, z);
136  new G4PVPlacement(placement, box.getVolume(), name + ".box", envelope, false, static_cast<int>(number));
137  }
138  }
139  }
140  }
141  } // VXD namespace
143 } // Belle2 namespace
Belle2::VXDGeoComponent::getLength
double getLength() const
get the length of the component
Definition: GeoVXDComponents.h:87
Belle2::VXDBoxTypesPar
The Class for VXD doc box.
Definition: VXDServiceGeometryPar.h:34
Belle2::VXDSlotsPar
The Class for Slot types.
Definition: VXDServiceGeometryPar.h:75
Belle2::VXDGeoComponent::getMaterial
const std::string & getMaterial() const
get the name of the Material for the component
Definition: GeoVXDComponents.h:77
Belle2::BkgSensitiveDetector
The Class for BeamBackground Sensitive Detector.
Definition: BkgSensitiveDetector.h:34
Belle2::geometry::Materials::get
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:65
Belle2::VXDGeoComponent::getVolume
G4LogicalVolume * getVolume() const
get the pointer to the logical volume, NULL if not yet created
Definition: GeoVXDComponents.h:73
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::VXDBoxPositionsPar
The Class for VXD doc box envelope.
Definition: VXDServiceGeometryPar.h:99
Belle2::VXDGeoComponent::getWidth
double getWidth() const
get the width of the component
Definition: GeoVXDComponents.h:81
Belle2::Unit::mm
static const double mm
[millimeters]
Definition: Unit.h:80
Belle2::VXDGeoComponent::setVolume
void setVolume(G4LogicalVolume *volume)
set the pointer to the logical volume
Definition: GeoVXDComponents.h:75
Belle2::VXD::GeoVXDServiceFactory
geometry::CreatorFactory< GeoVXDServiceCreator > GeoVXDServiceFactory("VXDServiceCreator")
Create factory instance so that the framework can instantiate the VXDServiceCreator.
Belle2::VXDGeoComponent::getHeight
double & getHeight()
get the height of the component
Definition: GeoVXDComponents.h:91
Belle2::gearbox::Interface::getNodes
std::vector< GearDir > getNodes(const std::string &path="") const
Get vector of GearDirs which point to all the nodes the given path evaluates to.
Definition: Interface.cc:31
Belle2::VXDGeoComponent
Class holding all parameters for an VXD geometry component.
Definition: GeoVXDComponents.h:65
Belle2::geometry::GeometryTypes
GeometryTypes
Flag indiciating the type of geometry to be used.
Definition: GeometryManager.h:39