Belle II Software  release-05-02-19
GeoHeavyMetalShieldCreator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Hyacinth Stypula, Benjamin Schwenker *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <vxd/geometry/GeoHeavyMetalShieldCreator.h>
12 
13 #include <geometry/Materials.h>
14 #include <geometry/CreatorFactory.h>
15 #include <geometry/utilities.h>
16 #include <framework/gearbox/GearDir.h>
17 #include <framework/gearbox/Unit.h>
18 #include <framework/logging/Logger.h>
19 
20 #include <cmath>
21 #include <boost/format.hpp>
22 #include <boost/algorithm/string.hpp>
23 #include <boost/math/special_functions/sign.hpp>
24 
25 #include <G4LogicalVolume.hh>
26 #include <G4PVPlacement.hh>
27 #include <G4AssemblyVolume.hh>
28 
29 // Shapes
30 #include <G4Box.hh>
31 #include <G4Polycone.hh>
32 #include <G4SubtractionSolid.hh>
33 
34 using namespace std;
35 using namespace boost;
36 
37 namespace Belle2 {
43  using namespace geometry;
44 
46  namespace VXD {
47 
49  CreatorFactory<GeoHeavyMetalShieldCreator> GeoHeavyMetalShieldFactory("HeavyMetalShieldCreator");
50 
51  HeavyMetalShieldGeometryPar GeoHeavyMetalShieldCreator::createConfiguration(const GearDir& param)
52  {
53  HeavyMetalShieldGeometryPar heavyMetalShieldGeometryPar;
54  //Read the definition of all shields
55  for (const GearDir& shield : param.getNodes("Shield")) {
56  VXDPolyConePar shieldPar(
57  shield.getString("@name"),
58  shield.getString("Material", "Air"),
59  shield.getAngle("minPhi", 0),
60  shield.getAngle("maxPhi", 2 * M_PI),
61  (shield.getNodes("Cutout").size() > 0),
62  shield.getLength("Cutout/width", 0.),
63  shield.getLength("Cutout/height", 0.),
64  shield.getLength("Cutout/depth", 0.)
65  );
66 
67  for (const GearDir& plane : shield.getNodes("Plane")) {
68  VXDPolyConePlanePar planePar(
69  plane.getLength("posZ"),
70  plane.getLength("innerRadius"),
71  plane.getLength("outerRadius")
72  );
73  shieldPar.getPlanes().push_back(planePar);
74  }
75 
76  heavyMetalShieldGeometryPar.getShields().push_back(shieldPar);
77  }
78  return heavyMetalShieldGeometryPar;
79  }
80 
81  void GeoHeavyMetalShieldCreator::createGeometry(const HeavyMetalShieldGeometryPar& parameters, G4LogicalVolume& topVolume,
83  {
84 
85  // Create the shields
86  for (const VXDPolyConePar& shield : parameters.getShields()) {
87 
88  string name = shield.getName();
89  double minZ(0), maxZ(0);
90 
91  // Create a polycone
92  double minPhi = shield.getMinPhi();
93  double dPhi = shield.getMaxPhi() - minPhi;
94  int nPlanes = shield.getPlanes().size();
95  if (nPlanes < 2) {
96  B2ERROR("Polycone needs at least two planes");
97  return ;
98  }
99  std::vector<double> z(nPlanes, 0);
100  std::vector<double> rMin(nPlanes, 0);
101  std::vector<double> rMax(nPlanes, 0);
102  int index(0);
103  minZ = numeric_limits<double>::infinity();
104  maxZ = -numeric_limits<double>::infinity();
105 
106 
107  for (const VXDPolyConePlanePar& plane : shield.getPlanes()) {
108  z[index] = plane.getPosZ() / Unit::mm;
109  minZ = min(minZ, z[index]);
110  maxZ = max(maxZ, z[index]);
111  rMin[index] = plane.getInnerRadius() / Unit::mm;
112  rMax[index] = plane.getOuterRadius() / Unit::mm;
113  ++index;
114  }
115 
116  G4VSolid* geoShield = new G4Polycone(name + " IR Shield", minPhi, dPhi, nPlanes, z.data(), rMin.data(), rMax.data());
117 
118  // Cutouts (if present)
119  if (shield.getDoCutOut()) {
120  double sizeX = shield.getCutOutWidth() / Unit::mm / 2.;
121  double sizeY = shield.getCutOutHeight() / Unit::mm / 2.;
122  double depth2 = shield.getCutOutDepth() / Unit::mm / 2.;
123  double sizeZ = (maxZ - minZ) / 2.;
124  double sign = math::sign<double>(minZ);
125  double minAbsZ = min(fabs(minZ), fabs(maxZ));
126 
127  G4ThreeVector origin1(0, 0, sign * (minAbsZ + sizeZ));
128  G4ThreeVector origin2(0, 0, sign * (minAbsZ + depth2));
129 
130  G4Box* box1 = new G4Box("Cutout", sizeX, sizeY, sizeZ);
131  G4Box* box2 = new G4Box("Cutout", 100 / Unit::mm, sizeY, depth2);
132 
133  geoShield = new G4SubtractionSolid(name + " IR Shield", geoShield, box1, G4Translate3D(origin1));
134  geoShield = new G4SubtractionSolid(name + " IR Shield", geoShield, box2, G4Translate3D(origin2));
135  }
136 
137  string materialName = shield.getMaterial();
138  G4Material* material = Materials::get(materialName);
139  if (!material) B2FATAL("Material '" << materialName << "', required by " << name << " IR Shield could not be found");
140 
141  G4LogicalVolume* volume = new G4LogicalVolume(geoShield, material, name + " IR Shield");
142  setColor(*volume, "#cc0000");
143  //setVisibility(*volume, false);
144  new G4PVPlacement(0, G4ThreeVector(0, 0, 0), volume, name + " IR Shield", &topVolume, false, 0);
145  }
146  }
147  }
149 }
Belle2::geometry::setColor
void setColor(G4LogicalVolume &volume, const std::string &color)
Set the color of a logical volume.
Definition: utilities.cc:107
Belle2::VXDPolyConePar::getPlanes
std::vector< VXDPolyConePlanePar > & getPlanes(void)
Get planes.
Definition: VXDPolyConePar.h:91
Belle2::VXD::GeoHeavyMetalShieldFactory
CreatorFactory< GeoHeavyMetalShieldCreator > GeoHeavyMetalShieldFactory("HeavyMetalShieldCreator")
Register the creator.
Belle2::HeavyMetalShieldGeometryPar
The Class for VXD Heavy Metal Shield.
Definition: HeavyMetalShieldGeometryPar.h:35
Belle2::VXDPolyConePlanePar
The Class for VXD Polycone Plane.
Definition: VXDPolyConePar.h:35
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::VXDPolyConePar
The Class for VXD PolyCone, possibly with coutouts.
Definition: VXDPolyConePar.h:65
Belle2::HeavyMetalShieldGeometryPar::getShields
std::vector< VXDPolyConePar > & getShields(void)
Get shields.
Definition: HeavyMetalShieldGeometryPar.h:41
Belle2::geometry::GeometryTypes
GeometryTypes
Flag indiciating the type of geometry to be used.
Definition: GeometryManager.h:39