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) Royal Holloway,
3University of London 2001 - 2024.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSAcceleratorComponent.hh"
20#include "BDSColours.hh"
21#include "BDSDebug.hh"
22#include "BDSException.hh"
23#include "BDSBeamPipe.hh"
24#include "BDSBeamPipeFactory.hh"
25#include "BDSBeamPipeInfo.hh"
26#include "BDSUtilities.hh"
27#include "BDSWireScanner.hh"
28
29#include "globals.hh"
30#include "G4LogicalVolume.hh"
31#include "G4PVPlacement.hh"
32#include "G4ThreeVector.hh"
33#include "G4Tubs.hh"
34#include "G4TwoVector.hh"
35#include "G4VisAttributes.hh"
36
37#include "CLHEP/Units/PhysicalConstants.h"
38
39#include <cmath>
40
41BDSWireScanner::BDSWireScanner(G4String nameIn,
42 G4double lengthIn,
43 BDSBeamPipeInfo* beamPipeInfoIn,
44 G4Material* wireMaterialIn,
45 G4double wireDiameterIn,
46 G4double wireLengthIn,
47 G4double wireAngleIn,
48 G4ThreeVector wireOffsetIn,
49 G4Colour* wireColourIn):
50 BDSAcceleratorComponent(nameIn, lengthIn, 0, "wirescanner", beamPipeInfoIn),
51 wireMaterial(wireMaterialIn),
52 wireDiameter(wireDiameterIn),
53 wireLength(wireLengthIn),
54 wireAngle(wireAngleIn),
55 wireOffset(wireOffsetIn),
56 wireColour(wireColourIn)
57{
58 if (wireDiameter <= 0)
59 {throw BDSException(__METHOD_NAME__, "Error: wireDiameter for \"" + name + "\" is not defined or must be greater than 0");}
60
61 if (wireLength <= 0)
62 {throw BDSException(__METHOD_NAME__, "Error: wire for \"" + name + "\" must be > 0.");}
63
64 // check whether the beam pipe will fit transversely (ignores presumably very small
65 // wire diameter). work out end points off wire including length and offset in x,y.
66 G4TwoVector offsetXY = G4TwoVector(wireOffset.x(), wireOffset.y());
67 G4TwoVector tipTop = G4TwoVector(0, 0.5*wireLength);
68 tipTop.rotate(wireAngle);
69 G4TwoVector tipBot = G4TwoVector(tipTop);
70 tipBot.rotate(CLHEP::pi);
71 tipTop += offsetXY;
72 tipBot += offsetXY;
73 G4double innerRadius = beamPipeInfo->IndicativeRadiusInner();
74 if (tipTop.mag() > innerRadius || tipBot.mag() > innerRadius)
75 {throw BDSException(__METHOD_NAME__, "wire for \"" + name + "\" is too big to fit in beam pipe give offsets.");}
76 if (!wireColour)
77 {wireColour = BDSColours::Instance()->GetColour("wirescanner");}
78}
79
81{
83 BDSBeamPipe* pipe = factory->CreateBeamPipe(name + "_beampipe",
86 RegisterDaughter(pipe);
87
88 // make the beam pipe container, this object's container
89 containerLogicalVolume = pipe->GetContainerLogicalVolume();
90 containerSolid = pipe->GetContainerSolid();
91
92 // register vacuum volume (for biasing)
94
95 // update extents
96 InheritExtents(pipe);
97
98 // update faces
101}
102
104{
106
107 G4VSolid* wire = BuildWireSolid();
108 G4LogicalVolume* wireLV = BuildWireLV(wire);
109
110 // placement rotation
111 G4RotationMatrix* wireRot = new G4RotationMatrix();
112 wireRot->rotateX(CLHEP::halfpi);
113 // want to rotate about unit Z but this has now changed
114 wireRot->rotateY(wireAngle);
115 RegisterRotationMatrix(wireRot);
116
117 // visualisation attributes
118 G4VisAttributes* wireVisAttr = new G4VisAttributes(*wireColour);
119 wireLV->SetVisAttributes(wireVisAttr);
120 RegisterVisAttributes(wireVisAttr);
121
122 // placement
123 G4LogicalVolume* vac = *(GetAcceleratorVacuumLogicalVolumes().begin()); // take the first one
124 G4PVPlacement* wirePV = new G4PVPlacement(wireRot, // rotation
125 wireOffset, // position
126 wireLV, // its logical volume
127 name + "_wire_pv", // its name
128 vac,
129 false, // no boolean operation
130 0, // copy number
133}
134
136{
137 G4Tubs* wire = new G4Tubs(name + "_wire_solid", // name
138 0, // inner radius
139 wireDiameter*0.5, // outer radius
140 wireLength*0.5, // half length
141 0, CLHEP::twopi); // start and finish angle
142 RegisterSolid(wire);
143 return wire;
144}
145
146
147G4LogicalVolume* BDSWireScanner::BuildWireLV(G4VSolid* solid)
148{
149 G4LogicalVolume* wireLV = new G4LogicalVolume(solid,
150 wireMaterial,
151 name + "_wire_lv");
152 RegisterLogicalVolume(wireLV);
153 return wireLV;
154}
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:33
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.
BDSWireScanner()=delete
Private default constructor to force the use of the supplied one.