Belle II Software development
G4TriangularPrism.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/* Own header. */
10#include <klm/eklm/geometry/G4TriangularPrism.h>
11
12/* CLHEP headers. */
13#include <CLHEP/Units/SystemOfUnits.h>
14
15/* C++ headers. */
16#include <cmath>
17#include <new>
18
19using namespace Belle2;
20
22 double r1, double phi1,
23 double r2, double phi2,
24 G4double halfZlen)
25{
26 double rl;
27 double rs;
28 double delta_phi;
29 double tg_alpha;
30 double alpha;
31 double sin_alpha;
32 double cos_alpha;
33 G4Transform3D t;
34 m_is = nullptr;
35 try {
36 m_tube = new G4Tubs("Tube_" + name, 0., std::max(r1, r2), halfZlen,
37 phi1, fabs(phi2 - phi1));
38 } catch (std::bad_alloc& ba) {
39 goto err_mem1;
40 }
41 if (r1 >= r2) {
42 rl = r1;
43 rs = r2;
44 } else {
45 rl = r2;
46 rs = r1;
47 }
48 delta_phi = phi2 - phi1;
49 tg_alpha = (rl / rs - cos(delta_phi)) / sin(delta_phi);
50 alpha = atan(tg_alpha);
51 sin_alpha = tg_alpha / sqrt(1.0 + tg_alpha * tg_alpha);
52 cos_alpha = 1.0 / sqrt(1.0 + tg_alpha * tg_alpha);
53 try {
54 m_box = new G4Box("Box_" + name, rl * sin_alpha,
55 rl * cos_alpha, halfZlen);
56 } catch (std::bad_alloc& ba) {
57 goto err_mem2;
58 }
59 if (r1 >= r2)
60 t = G4RotateZ3D((phi1 + alpha) * CLHEP::rad - 90.0 * CLHEP::deg);
61 else
62 t = G4RotateZ3D((phi2 - alpha) * CLHEP::rad + 90.0 * CLHEP::deg);
63 try {
64 m_is = new G4IntersectionSolid(name, m_tube, m_box, t);
65 } catch (std::bad_alloc& ba) {
66 goto err_mem3;
67 }
68 return;
69err_mem3:
70 delete m_box;
71err_mem2:
72 delete m_tube;
73err_mem1:
74 throw (std::bad_alloc());
75}
76
78{
79}
G4IntersectionSolid * m_is
Intersection.
G4TriangularPrism(const G4String &name, double r1, double phi1, double r2, double phi2, G4double halfZlen)
Constructor.
double atan(double a)
atan for double
Definition: beamHelpers.h:34
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.