BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSWireScanner.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSAcceleratorComponent.hh"
19#include "BDSColours.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSBeamPipe.hh"
23#include "BDSBeamPipeFactory.hh"
24#include "BDSBeamPipeInfo.hh"
25#include "BDSUtilities.hh"
26#include "BDSWireScanner.hh"
27
28#include "globals.hh"
29#include "G4LogicalVolume.hh"
30#include "G4PVPlacement.hh"
31#include "G4ThreeVector.hh"
32#include "G4Tubs.hh"
33#include "G4TwoVector.hh"
34#include "G4VisAttributes.hh"
35
36#include "CLHEP/Units/PhysicalConstants.h"
37
38#include <cmath>
39
40BDSWireScanner::BDSWireScanner(const G4String& nameIn,
41 G4double lengthIn,
42 BDSBeamPipeInfo* beamPipeInfoIn,
43 G4Material* wireMaterialIn,
44 G4double wireDiameterIn,
45 G4double wireLengthIn,
46 G4double wireAngleIn,
47 const G4ThreeVector& wireOffsetIn,
48 G4Colour* wireColourIn):
49 BDSAcceleratorComponent(nameIn, lengthIn, 0, "wirescanner", beamPipeInfoIn),
50 wireMaterial(wireMaterialIn),
51 wireDiameter(wireDiameterIn),
52 wireLength(wireLengthIn),
53 wireAngle(wireAngleIn),
54 wireOffset(wireOffsetIn),
55 wireColour(wireColourIn)
56{
57 if (wireDiameter <= 0)
58 {throw BDSException(__METHOD_NAME__, "Error: wireDiameter for \"" + name + "\" is not defined or must be greater than 0");}
59
60 if (wireLength <= 0)
61 {throw BDSException(__METHOD_NAME__, "Error: wire for \"" + name + "\" must be > 0.");}
62
63 // check whether the beam pipe will fit transversely (ignores presumably very small
64 // wire diameter). work out end points off wire including length and offset in x,y.
65 G4TwoVector offsetXY = G4TwoVector(wireOffset.x(), wireOffset.y());
66 G4TwoVector tipTop = G4TwoVector(0, 0.5*wireLength);
67 tipTop.rotate(wireAngle);
68 G4TwoVector tipBot = G4TwoVector(tipTop);
69 tipBot.rotate(CLHEP::pi);
70 tipTop += offsetXY;
71 tipBot += offsetXY;
72 G4double innerRadius = beamPipeInfo->IndicativeRadiusInner();
73 if (tipTop.mag() > innerRadius || tipBot.mag() > innerRadius)
74 {throw BDSException(__METHOD_NAME__, "wire for \"" + name + "\" is too big to fit in beam pipe give offsets.");}
75 if (!wireColour)
76 {wireColour = BDSColours::Instance()->GetColour("wirescanner");}
77}
78
80{
82 BDSBeamPipe* pipe = factory->CreateBeamPipe(name + "_beampipe",
85 RegisterDaughter(pipe);
86
87 // make the beam pipe container, this object's container
88 containerLogicalVolume = pipe->GetContainerLogicalVolume();
89 containerSolid = pipe->GetContainerSolid();
90
91 // register vacuum volume (for biasing)
93
94 // update extents
95 InheritExtents(pipe);
96
97 // update faces
100}
101
103{
105
106 G4VSolid* wire = BuildWireSolid();
107 G4LogicalVolume* wireLV = BuildWireLV(wire);
108
109 // placement rotation
110 G4RotationMatrix* wireRot = new G4RotationMatrix();
111 wireRot->rotateX(CLHEP::halfpi);
112 // want to rotate about unit Z but this has now changed
113 wireRot->rotateY(wireAngle);
114 RegisterRotationMatrix(wireRot);
115
116 // visualisation attributes
117 G4VisAttributes* wireVisAttr = new G4VisAttributes(*wireColour);
118 wireLV->SetVisAttributes(wireVisAttr);
119 RegisterVisAttributes(wireVisAttr);
120
121 // placement
122 G4LogicalVolume* vac = *(GetAcceleratorVacuumLogicalVolumes().begin()); // take the first one
123 G4PVPlacement* wirePV = new G4PVPlacement(wireRot, // rotation
124 wireOffset, // position
125 wireLV, // its logical volume
126 name + "_wire_pv", // its name
127 vac,
128 false, // no boolean operation
129 0, // copy number
132}
133
135{
136 G4Tubs* wire = new G4Tubs(name + "_wire_solid", // name
137 0, // inner radius
138 wireDiameter*0.5, // outer radius
139 wireLength*0.5, // half length
140 0, CLHEP::twopi); // start and finish angle
141 RegisterSolid(wire);
142 return wire;
143}
144
145G4LogicalVolume* BDSWireScanner::BuildWireLV(G4VSolid* solid)
146{
147 G4LogicalVolume* wireLV = new G4LogicalVolume(solid,
148 wireMaterial,
149 name + "_wire_lv");
150 RegisterLogicalVolume(wireLV);
151 return wireLV;
152}
Abstract class that represents a component of an accelerator.
void SetAcceleratorVacuumLogicalVolume(G4LogicalVolume *accVacLVIn)
const G4String name
Const protected member variable that may not be changed by derived classes.
virtual void SetOutputFaceNormal(const G4ThreeVector &output)
Allow updating of face normals. Virtual so derived class may apply it to daughters.
static G4bool checkOverlaps
Useful variable often used in construction.
virtual std::set< G4LogicalVolume * > GetAcceleratorVacuumLogicalVolumes() const
Access the 'vacuum' volume(s) in this component if any. Default is empty set.
virtual void SetInputFaceNormal(const G4ThreeVector &input)
Allow updating of face normals. Virtual so derived class may apply it to daughters.
G4double chordLength
Protected member variable that can be modified by derived classes.
BDSBeamPipeInfo * beamPipeInfo
Optional beam pipe recipe that is written out to the survey if it exists.
The main interface for using the beam pipe factories.
static BDSBeamPipeFactory * Instance()
Singleton accessor.
Holder class for all information required to describe a beam pipe model.
A holder class for a piece of beam pipe geometry.
G4LogicalVolume * GetVacuumLogicalVolume() const
Access the vacuum volume to set fields and limits.
G4ThreeVector InputFaceNormal() const
Accessor.
G4ThreeVector OutputFaceNormal() const
Accessor.
G4Colour * GetColour(G4double red, G4double green, G4double blue, G4double alpha=1)
Get a cached anonymous colour by values.
static BDSColours * Instance()
singleton pattern
Definition BDSColours.cc:32
General exception with possible name of object and message.
G4LogicalVolume * GetContainerLogicalVolume() const
Accessor - see member for more info.
void InheritExtents(BDSGeometryComponent const *const anotherComponent)
Update the extents of this object with those of another object.
void RegisterRotationMatrix(G4RotationMatrix *rotationMatrix)
void RegisterDaughter(BDSGeometryComponent *anotherComponent)
void RegisterLogicalVolume(G4LogicalVolume *logicalVolume)
void RegisterPhysicalVolume(G4VPhysicalVolume *physicalVolume)
G4VSolid * GetContainerSolid() const
Accessor - see member for more info.
void RegisterVisAttributes(G4VisAttributes *visAttribute)
void RegisterSolid(G4VSolid *solid)
virtual void BuildContainerLogicalVolume()
virtual void Build()
virtual G4VSolid * BuildWireSolid()
Allow overriding of certain bits of construction.
virtual G4LogicalVolume * BuildWireLV(G4VSolid *solid)
Allow overriding of certain bits of construction.