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