g4system
Loading...
Searching...
No Matches
modifier_transform.cc
Go to the documentation of this file.
1
5
6#include "g4objectsFactory.h"
7
8#include <CLHEP/Units/SystemOfUnits.h>
9
10#include <cmath>
11#include <cstdlib>
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace {
17
18class TransformProbe : public G4ObjectsFactory
19{
20public:
23};
24
25bool close_to(double actual, double expected) {
26 return std::abs(actual - expected) < 1.0e-9;
27}
28
29} // namespace
30
31int main() {
32 const std::shared_ptr<GLogger> logger;
33 GVolume volume(logger, "test", {
34 "modified", "G4Box", "1*cm, 1*cm, 1*cm", "G4_AIR", "root",
35 "1*cm, 2*cm, 3*cm", "0*deg, 0*deg, 0*deg", "active", "NULL",
36 "1", "1", "778899", "1", "NULL", "NULL", "NULL", "NULL", "NULL",
37 "1", "modifier transform test", "default", "1"
38 });
39 volume.applyShift("4*cm, 5*cm, 6*cm");
40 volume.applyTilt("0*deg, 0*deg, 90*deg");
41
42 const auto position = TransformProbe::getPosition(&volume);
43 if (!close_to(position.x(), 5.0 * CLHEP::cm) ||
44 !close_to(position.y(), 7.0 * CLHEP::cm) ||
45 !close_to(position.z(), 9.0 * CLHEP::cm)) {
46 return EXIT_FAILURE;
47 }
48
49 std::unique_ptr<G4RotationMatrix> rotation(TransformProbe::getRotation(&volume));
50 const auto rotated = *rotation * G4ThreeVector(1.0, 0.0, 0.0);
51 if (!close_to(rotated.x(), 0.0) || !close_to(rotated.y(), 1.0) || !close_to(rotated.z(), 0.0)) {
52 return EXIT_FAILURE;
53 }
54
55 return EXIT_SUCCESS;
56}
Base class orchestrating the conversion of a GVolume into a Geant4 representation.
static G4RotationMatrix * getRotation(const GVolume *s)
Parse rotation string and build a Geant4 rotation matrix.
static G4ThreeVector getPosition(const GVolume *s)
Parse position and optional shift strings to compute placement translation.
void applyShift(std::optional< std::string > s)
Abstract factory that converts a GEMC DB GVolume into Geant4 objects.
int main()