Belle II Software  release-08-01-10
GeoCOILCreator.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 <structure/geometry/GeoCOILCreator.h>
10 #include <structure/dbobjects/COILGeometryPar.h>
11 
12 #include <geometry/Materials.h>
13 #include <geometry/CreatorFactory.h>
14 
15 #include <framework/gearbox/Unit.h>
16 #include <framework/gearbox/GearDir.h>
17 #include <framework/logging/Logger.h>
18 
19 #include <framework/database/DBObjPtr.h>
20 #include <framework/database/DBImportObjPtr.h>
21 #include <framework/database/IntervalOfValidity.h>
22 
23 #include <cmath>
24 
25 #include <G4LogicalVolume.hh>
26 #include <G4PVPlacement.hh>
27 #include <G4Tubs.hh>
28 #include <G4Transform3D.hh>
29 #include <G4VisAttributes.hh>
30 
31 #include <iostream>
32 
33 /* Geant4 default unit
34  millimeter (mm)
35  nanosecond (ns)
36  Mega electron Volt (MeV)
37  positron charge (eplus)
38  degree Kelvin (kelvin)
39  the amount of substance (mole)
40  luminous intensity (candela)
41  radian (radian)
42  steradian (steradian)
43 */
44 
45 
46 using namespace std;
47 
48 namespace Belle2 {
54  using namespace geometry;
55 
56  namespace coil {
57  //-----------------------------------------------------------------
58  // Register the Creator
59  //-----------------------------------------------------------------
60 
61  geometry::CreatorFactory<GeoCOILCreator> GeoCOILFactory("COILCreator");
62  //-----------------------------------------------------------------
63  // Implementation
64  //-----------------------------------------------------------------
65 
66  GeoCOILCreator::GeoCOILCreator()
67  {
68  m_VisAttributes.clear();
69  m_VisAttributes.push_back(new G4VisAttributes(false)); // for "invisible"
70  }
71 
72 
73  GeoCOILCreator::~GeoCOILCreator()
74  {
75  for (G4VisAttributes* visAttr : m_VisAttributes) delete visAttr;
76  m_VisAttributes.clear();
77  }
78 
79  //Old way of creating geometry
80  void GeoCOILCreator::create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes type)
81  {
82  COILGeometryPar config = readConfiguration(content);
83  createGeometry(config, topVolume, type);
84  }
85 
86  //Create config obgects and store in database
87  void GeoCOILCreator::createPayloads(const GearDir& content, const IntervalOfValidity& iov)
88  {
90  importObj.construct(readConfiguration(content));
91  importObj.import(iov);
92  }
93 
94  //Create geometry from database
95  void GeoCOILCreator::createFromDB(const std::string& name, G4LogicalVolume& topVolume, geometry::GeometryTypes type)
96  {
98  if (!dbObj) {
99  // Check that we found the object and if not report the problem
100  B2FATAL("No configuration for " << name << " found.");
101  }
102  createGeometry(*dbObj, topVolume, type);
103  }
104 
105 
106  // Write COILGeometryPar object from GearBox content
107  COILGeometryPar GeoCOILCreator::readConfiguration(const GearDir& content)
108  {
109  COILGeometryPar parameters;
110 
111  // Global parameters
112  parameters.setGlobalRotAngle(content.getAngle("Rotation") / Unit::rad);
113  parameters.setGlobalOffsetZ(content.getLength("OffsetZ") / Unit::mm);
114 
115  // Cryostat
116  parameters.setCryoMaterial(content.getString("Cryostat/Material", "Air"));
117  parameters.setCryoRmin(content.getLength("Cryostat/Rmin") / Unit::mm);
118  parameters.setCryoRmax(content.getLength("Cryostat/Rmax") / Unit::mm);
119  parameters.setCryoLength(content.getLength("Cryostat/HalfLength") / Unit::mm);
120 
121  //Cavity #1
122  parameters.setCav1Material(content.getString("Cavity1/Material", "Air"));
123  parameters.setCav1Rmin(content.getLength("Cavity1/Rmin") / Unit::mm);
124  parameters.setCav1Rmax(content.getLength("Cavity1/Rmax") / Unit::mm);
125  parameters.setCav1Length(content.getLength("Cavity1/HalfLength") / Unit::mm);
126 
127  // Radiation Shield
128  parameters.setShieldMaterial(content.getString("RadShield/Material", "Air"));
129  parameters.setShieldRmin(content.getLength("RadShield/Rmin") / Unit::mm);
130  parameters.setShieldRmax(content.getLength("RadShield/Rmax") / Unit::mm);
131  parameters.setShieldLength(content.getLength("RadShield/HalfLength") / Unit::mm);
132 
133  // Cavity #2
134  parameters.setCav2Material(content.getString("Cavity2/Material", "Air"));
135  parameters.setCav2Rmin(content.getLength("Cavity2/Rmin") / Unit::mm);
136  parameters.setCav2Rmax(content.getLength("Cavity2/Rmax") / Unit::mm);
137  parameters.setCav2Length(content.getLength("Cavity2/HalfLength") / Unit::mm);
138 
139  // Coil
140  parameters.setCoilMaterial(content.getString("Coil/Material", "Air"));
141  parameters.setCoilRmin(content.getLength("Coil/Rmin") / Unit::mm);
142  parameters.setCoilRmax(content.getLength("Coil/Rmax") / Unit::mm);
143  parameters.setCoilLength(content.getLength("Coil/HalfLength") / Unit::mm);
144 
145  return parameters;
146  }
147 
148  // Create geometry from COILGeometryPar object
149  void GeoCOILCreator::createGeometry(const COILGeometryPar& parameters, G4LogicalVolume& topVolume, GeometryTypes)
150  {
151  // Global parameters
152  double GlobalRotAngle = parameters.getGlobalRotAngle();
153  double GlobalOffsetZ = parameters.getGlobalOffsetZ();
154 
155 
156  // Cryostat
158 
159  string strMatCryo = parameters.getCryoMaterial();
160  double CryoRmin = parameters.getCryoRmin();
161  double CryoRmax = parameters.getCryoRmax();
162  double CryoLength = parameters.getCryoLength();
163 
164  G4Material* matCryostat = Materials::get(strMatCryo);
165  G4Tubs* CryoTube =
166  new G4Tubs("Cryostat", CryoRmin, CryoRmax, CryoLength, 0.0, M_PI * 2.0);
167  G4LogicalVolume* CryoLV =
168  new G4LogicalVolume(CryoTube, matCryostat, "LVCryo", 0, 0, 0);
169  new G4PVPlacement(G4TranslateZ3D(GlobalOffsetZ) * G4RotateZ3D(GlobalRotAngle),
170  CryoLV, "PVCryo", &topVolume, false, 0);
171 
172 
173  // Cavity #1
175  string strMatCav1 = parameters.getCav1Material();
176  double Cav1Rmin = parameters.getCav1Rmin();
177  double Cav1Rmax = parameters.getCav1Rmax();
178  double Cav1Length = parameters.getCav1Length();
179 
180  G4Material* matCav1 = Materials::get(strMatCav1);
181 
182  G4Tubs* Cav1Tube =
183  new G4Tubs("Cavity1", Cav1Rmin, Cav1Rmax, Cav1Length, 0.0, M_PI * 2.0);
184  G4LogicalVolume* Cav1LV =
185  new G4LogicalVolume(Cav1Tube, matCav1, "LVCav1", 0, 0, 0);
186  m_VisAttributes.push_back(new G4VisAttributes(G4Colour(0., 1., 0.)));
187  Cav1LV->SetVisAttributes(m_VisAttributes.back());
188  new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), Cav1LV, "PVCav1", CryoLV, false, 0);
189 
190 
191  // Rad Shield
193  string strMatShield = parameters.getShieldMaterial();
194  double ShieldRmin = parameters.getShieldRmin();
195  double ShieldRmax = parameters.getShieldRmax();
196  double ShieldLength = parameters.getShieldLength();
197 
198  G4Material* matShield = Materials::get(strMatShield);
199 
200  G4Tubs* ShieldTube =
201  new G4Tubs("RadShield", ShieldRmin, ShieldRmax, ShieldLength, 0.0, M_PI * 2.0);
202  G4LogicalVolume* ShieldLV =
203  new G4LogicalVolume(ShieldTube, matShield, "LVShield", 0, 0, 0);
204  m_VisAttributes.push_back(new G4VisAttributes(G4Colour(1., 1., 0.)));
205  ShieldLV->SetVisAttributes(m_VisAttributes.back());
206  new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), ShieldLV, "PVShield", Cav1LV, false, 0);
207 
208 
209  // Cavity #2
211  string strMatCav2 = parameters.getCav2Material();
212  double Cav2Rmin = parameters.getCav2Rmin();
213  double Cav2Rmax = parameters.getCav2Rmax();
214  double Cav2Length = parameters.getCav2Length();
215 
216  G4Material* matCav2 = Materials::get(strMatCav2);
217 
218  G4Tubs* Cav2Tube =
219  new G4Tubs("Cavity2", Cav2Rmin, Cav2Rmax, Cav2Length, 0.0, M_PI * 2.0);
220  G4LogicalVolume* Cav2LV =
221  new G4LogicalVolume(Cav2Tube, matCav2, "LVCav2", 0, 0, 0);
222  m_VisAttributes.push_back(new G4VisAttributes(G4Colour(1., 1., 1.)));
223  Cav2LV->SetVisAttributes(m_VisAttributes.back());
224  new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), Cav2LV, "PVCav2", ShieldLV, false, 0);
225 
226 
227  // Coil
229  string strMatCoil = parameters.getCoilMaterial();
230  double CoilRmin = parameters.getCoilRmin();
231  double CoilRmax = parameters.getCoilRmax();
232  double CoilLength = parameters.getCoilLength();
233 
234  G4Material* matCoil = Materials::get(strMatCoil);
235 
236  G4Tubs* CoilTube =
237  new G4Tubs("Coil", CoilRmin, CoilRmax, CoilLength, 0.0, M_PI * 2.0);
238  G4LogicalVolume* CoilLV =
239  new G4LogicalVolume(CoilTube, matCoil, "LVCoil", 0, 0, 0);
240  m_VisAttributes.push_back(new G4VisAttributes(G4Colour(0., 1., 1.)));
241  CoilLV->SetVisAttributes(m_VisAttributes.back());
242  new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), CoilLV, "PVCoil", Cav2LV, false, 0);
243 
244  }
245  }
247 }
248 
The Class for COIL geometry parameters.
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:36
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
A class that describes the interval of experiments/runs for which an object in the database is valid.
GeometryTypes
Flag indiciating the type of geometry to be used.
Abstract base class for different kinds of events.