Belle II Software  release-08-01-10
ClawCreator.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 <beast/claw/geometry/ClawCreator.h>
10 #include <beast/claw/simulation/SensitiveDetector.h>
11 
12 #include <geometry/Materials.h>
13 #include <geometry/CreatorFactory.h>
14 #include <framework/gearbox/GearDir.h>
15 #include <framework/logging/Logger.h>
16 
17 #include <boost/format.hpp>
18 #include <boost/foreach.hpp>
19 #include <boost/algorithm/string.hpp>
20 
21 #include <G4LogicalVolume.hh>
22 #include <G4PVPlacement.hh>
23 
24 //Shapes
25 #include <G4Box.hh>
26 #include "G4SubtractionSolid.hh"
27 #include <G4UserLimits.hh>
28 
29 //Visualization Attributes
30 #include <G4VisAttributes.hh>
31 
32 using namespace std;
33 using namespace boost;
34 
35 namespace Belle2 {
42  namespace claw {
43 
44  // Register the creator
47 
48  ClawCreator::ClawCreator(): m_sensitive(0)
49  {
50  //m_sensitive = new SensitiveDetector();
51  }
52 
54  {
55  if (m_sensitive) delete m_sensitive;
56  }
57 
58  void ClawCreator::create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes /* type */)
59  {
60 
62 
63  //lets get the stepsize parameter with a default value of 5 µm
64  double stepSize = content.getLength("stepSize", 5 * CLHEP::um);
65 
66  G4VisAttributes* red = new G4VisAttributes(G4Colour(1, 0, 0));
67  red->SetForceAuxEdgeVisible(true);
68  G4VisAttributes* green = new G4VisAttributes(G4Colour(0, 1, 0));
69  green->SetForceAuxEdgeVisible(true);
70  G4VisAttributes* gray = new G4VisAttributes(G4Colour(.5, .5, .5));
71  gray->SetForceAuxEdgeVisible(true);
72 
73  G4VisAttributes* coppercolor = new G4VisAttributes(G4Colour(218. / 255., 138. / 255., 103. / 255.));
74  coppercolor->SetForceAuxEdgeVisible(true);
75 
76  int detID = 0;
77  //Lets loop over all the Active nodes
78  BOOST_FOREACH(const GearDir & activeParams, content.getNodes("Active")) {
79  /*
80  double x_pos[100];
81  double y_pos[100];
82  double x_off[100];
83  double y_off[100];
84  double z_pos[100];
85  double phi[100];
86  double thetaZ[100];
87  double r[100];
88  int dimx = 0;
89  int dimy = 0;
90  int dimx_offset = 0;
91  int dimy_offset = 0;
92  int dimz = 0;
93  int dimr_dia = 0;
94  for (double x_offset : activeParams.getArray("x_offset", {0})) {
95  x_offset *= CLHEP::cm;
96  x_off[dimx_offset] = x_offset;
97  dimx_offset++;
98  }
99  for (double y_offset : activeParams.getArray("y_offset", {0})) {
100  y_offset *= CLHEP::cm;
101  y_off[dimy_offset] = y_offset;
102  dimy_offset++;
103  }
104  for (double x : activeParams.getArray("x", {0})) {
105  x *= CLHEP::cm;
106  x_pos[dimx] = x + x_off[dimx];
107  dimx++;
108  }
109  for (double y : activeParams.getArray("y", {0})) {
110  y *= CLHEP::cm;
111  y_pos[dimy] = y + y_off[dimy];
112  dimy++;
113  }
114  for (double z : activeParams.getArray("z", {0})) {
115  z *= CLHEP::cm;
116  z_pos[dimz] = z;
117  if (dimx != 0 && dimy != 0)
118  r[dimz] = sqrt(x_pos[dimz] * x_pos[dimz] + y_pos[dimz] * y_pos[dimz]);
119  dimz++;
120  }
121  int dimPhi = 0;
122  for (double Phi : activeParams.getArray("Phi", {0})) {
123  phi[dimPhi] = Phi;
124  dimPhi++;
125  }
126  int dimThetaZ = 0;
127  for (double ThetaZ : activeParams.getArray("ThetaZ", {0})) {
128  thetaZ[dimThetaZ] = ThetaZ;
129  dimThetaZ++;
130  }
131  if (dimx == 0 && dimy == 0) {
132  for (double r_dia : activeParams.getArray("r_dia", {0})) {
133  r_dia *= CLHEP::cm;
134  r[dimr_dia] = r_dia;
135  dimr_dia++;
136  }
137  }
138  */
139  int Nscint = activeParams.getInt("Nscint");
140  G4double x = activeParams.getLength("x") * CLHEP::cm;
141  G4double y = activeParams.getLength("y") * CLHEP::cm;
142  G4double z = activeParams.getLength("z_claw") * CLHEP::cm;
143  /*G4double r = 0;
144  if (x == 0 && y == 0)
145  r = activeParams.getLength("r_claw") * CLHEP::cm;
146  else
147  r = sqrt(x * x + y * y);*/
148  //G4double phi = activeParams.getAngle("Phi");
149  //G4double thetaZ = activeParams.getAngle("ThetaZ");
150  G4double dx_board = activeParams.getLength("dx_board") / 2.*CLHEP::cm;
151  G4double dy_board = activeParams.getLength("dy_board") / 2.*CLHEP::cm;
152  G4double dz_board = activeParams.getLength("dz_board") / 2.*CLHEP::cm;
153  G4double dz_Culayer = activeParams.getLength("dz_Culayer") / 2.*CLHEP::cm;
154  G4double dx_scint = activeParams.getLength("dx_scint") / 2.*CLHEP::cm;
155  G4double dy_scint = activeParams.getLength("dy_scint") / 2.*CLHEP::cm;
156  G4double dz_scint = activeParams.getLength("dz_scint") / 2.*CLHEP::cm;
157  G4double Al_width = activeParams.getLength("Al_width") / 2.*CLHEP::cm;
158  G4double dx_Al = dx_scint + Al_width;
159  G4double dy_Al = dy_scint + Al_width;
160  G4double dz_Al = dz_scint + Al_width;
161  G4double dx_air = dx_Al;
162  G4double dy_air = dy_Al * Nscint;
163  G4double dz_air = dz_board + 2. * dz_Culayer + dz_Al;
164  //cout << " dx sol 1 " << dx_air << " sol 2 " << dx_board << endl;
165  //cout << " dy sol 1 " << dy_air << " sol 2 " << dy_board << endl;
166 
167  //create air volume engloging ladder + scintillator + Al foil
168  G4Box* s_air = new G4Box("s_air", dx_air, dy_air, dz_air);
169  G4LogicalVolume* l_air = new G4LogicalVolume(s_air, geometry::Materials::get("G4_AIR"), "l_air");
170 
171 
172  //create claw G10 board
173  G4Box* s_board = new G4Box("s_board", dx_board, dy_board, dz_board);
174  G4LogicalVolume* l_board = new G4LogicalVolume(s_board, geometry::Materials::get("G10"), "l_board");
175  l_board->SetVisAttributes(green);
176 
177  G4double r_board = dz_air - 2. * dz_Culayer - dz_board;
178 
179  //create copper layer on each side of the G10 board
180  G4Box* s_Culayer = new G4Box("s_Culayer", dx_board, dy_board, dz_Culayer);
181  G4LogicalVolume* l_Culayer = new G4LogicalVolume(s_Culayer, geometry::Materials::get("Cu"), "l_Culayer");
182  l_Culayer->SetVisAttributes(coppercolor);
183 
184  G4double r_Culayer_bot = r_board - dz_board - dz_Culayer;
185  G4double r_Culayer_top = r_board + dz_board + dz_Culayer;
186  //cout << " cu bot sol 1 " << r_Culayer_bot << " sol 2 " << -dz_air + dz_Culayer<< endl;
187 
188  //create scintillator and Al foil around it
189  G4VSolid* s_scint = new G4Box("s_scint", dx_scint, dy_scint, dz_scint);
190  G4VSolid* s_Al = new G4Box("s_Al", dx_Al, dy_Al, dz_Al);
191  s_Al = new G4SubtractionSolid("s_Al", s_Al, s_scint, 0, G4ThreeVector(0, 0, 0));
192  G4LogicalVolume* l_Al = new G4LogicalVolume(s_Al, geometry::Materials::get("Al"), "l_Al");
193  l_Al->SetVisAttributes(gray);
194 
195  G4LogicalVolume* l_scint = new G4LogicalVolume(s_scint, geometry::Materials::get("G4_POLYSTYRENE"), "l_scint", 0, m_sensitive);
196  l_scint->SetVisAttributes(red);
197  //Lets limit the Geant4 stepsize inside the volume
198  l_scint->SetUserLimits(new G4UserLimits(stepSize));
199 
200  G4double r_Al = r_Culayer_bot - dz_Culayer - dz_Al;
201  //cout << " dz_air " << dz_air << " x2 " << 2. * dz_air << " r_Al " << r_Al << " tot " << r_Al + dz_Al << " sol3 " << r_Culayer_top + dz_Culayer + dz_Al << endl;
202  double z_0 = -dy_air + dy_Al;
203 
204  //for(int i = 0; i < dimz; i++) {
205 
206  //G4Transform3D transform = G4RotateZ3D(-M_PI / 2 + phi[i]) * G4Translate3D(0, r[i], z_pos[i]) * G4RotateX3D(-M_PI / 2 - thetaZ[i]);
207  //G4Transform3D transform = G4RotateZ3D(-M_PI / 2 + phi) * G4Translate3D(0, r, z) * G4RotateX3D(-M_PI / 2 - thetaZ);
208  G4Transform3D transform = G4Translate3D(x, y, z);
209  new G4PVPlacement(transform, l_air, "p_air", &topVolume, false, 1);
210  new G4PVPlacement(0, G4ThreeVector(0, 0, r_board), l_board, "p_board", l_air, false, 1);
211  new G4PVPlacement(0, G4ThreeVector(0, 0, r_Culayer_bot), l_Culayer, "p_Culayer_bot", l_air, false, 1);
212  new G4PVPlacement(0, G4ThreeVector(0, 0, r_Culayer_top), l_Culayer, "p_Culayer_top", l_air, false, 1);
213 
214  for (int j = 0; j < Nscint; j++) {
215  double i_z = z_0 + j * 2. * dy_Al;
216 
217  new G4PVPlacement(0, G4ThreeVector(0, i_z, r_Al), l_Al, "p_Al", l_air, false, 1);
218  new G4PVPlacement(0, G4ThreeVector(0, i_z, r_Al), l_scint, "p_scint", l_air, false, detID);
219  B2INFO("Phase1-CLAWS-" << detID << " placed at: " << transform.getTranslation() << " mm");
220  detID++;
221  //}
222  }
223  }
224  }
225  } // claw namespace
227 } // Belle2 namespace
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
virtual ~ClawCreator()
Destructor.
Definition: ClawCreator.cc:53
virtual void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type)
Creation of the detector geometry from Gearbox (XML).
Definition: ClawCreator.cc:58
SensitiveDetector * m_sensitive
SensitiveDetector CLAW.
Definition: ClawCreator.h:46
Sensitive Detector implementation of the CLAW detector.
double getLength(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard length unit.
Definition: Interface.h:259
int getInt(const std::string &path="") const noexcept(false)
Get the parameter path as a int.
Definition: Interface.cc:60
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:63
geometry::CreatorFactory< ClawCreator > ClawFactory("CLAWCreator")
Creator creates the CLAW geometry.
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.