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