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 - 2023.
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 BDSAcceleratorComponent(nameIn, lengthIn, 0, "wirescanner", beamPipeInfoIn),
50 wireMaterial(wireMaterialIn),
51 wireDiameter(wireDiameterIn),
52 wireLength(wireLengthIn),
53 wireAngle(wireAngleIn),
54 wireOffset(wireOffsetIn)
55{
56 if (wireDiameter <= 0)
57 {throw BDSException(__METHOD_NAME__, "Error: wireDiameter for \"" + name + "\" is not defined or must be greater than 0");}
58
59 if (wireLength <= 0)
60 {throw BDSException(__METHOD_NAME__, "Error: wire for \"" + name + "\" must be > 0.");}
61
62 // check whether the beam pipe will fit transversely (ignores presumably very small
63 // wire diameter). work out end points off wire including length and offset in x,y.
64 G4TwoVector offsetXY = G4TwoVector(wireOffset.x(), wireOffset.y());
65 G4TwoVector tipTop = G4TwoVector(0, 0.5*wireLength);
66 tipTop.rotate(wireAngle);
67 G4TwoVector tipBot = G4TwoVector(tipTop);
68 tipBot.rotate(CLHEP::pi);
69 tipTop += offsetXY;
70 tipBot += offsetXY;
71 G4double innerRadius = beamPipeInfo->IndicativeRadiusInner();
72 if (tipTop.mag() > innerRadius || tipBot.mag() > innerRadius)
73 {throw BDSException(__METHOD_NAME__, "wire for \"" + name + "\" is too big to fit in beam pipe give offsets.");}
74}
75
77{
79 BDSBeamPipe* pipe = factory->CreateBeamPipe(name + "_beampipe",
82 RegisterDaughter(pipe);
83
84 // make the beam pipe container, this object's container
85 containerLogicalVolume = pipe->GetContainerLogicalVolume();
86 containerSolid = pipe->GetContainerSolid();
87
88 // register vacuum volume (for biasing)
90
91 // update extents
92 InheritExtents(pipe);
93
94 // update faces
97}
98
100{
102
103 G4Tubs* wire = new G4Tubs(name + "_wire_solid", // name
104 0, // inner radius
105 wireDiameter*0.5, // outer radius
106 wireLength*0.5, // half length
107 0, CLHEP::twopi); // start and finish angle
108 RegisterSolid(wire);
109
110 G4LogicalVolume* wireLV = new G4LogicalVolume(wire, // solid
111 wireMaterial, // material
112 name + "_wire_lv"); // name
113 RegisterLogicalVolume(wireLV);
114 RegisterSensitiveVolume(wireLV, BDSSDType::wirecomplete);
115
116 // placement rotation
117 G4RotationMatrix* wireRot = new G4RotationMatrix();
118 wireRot->rotateX(CLHEP::halfpi);
119 // want to rotate about unit Z but this has now changed
120 wireRot->rotateY(wireAngle);
121 RegisterRotationMatrix(wireRot);
122
123 // visualisation attributes
124 G4VisAttributes* wireVisAttr = new G4VisAttributes(*BDSColours::Instance()->GetColour("wirescanner"));
125 wireLV->SetVisAttributes(wireVisAttr);
126 RegisterVisAttributes(wireVisAttr);
127
128 // placement
129 G4LogicalVolume* vac = *(GetAcceleratorVacuumLogicalVolumes().begin()); // take the first one
130 G4PVPlacement* wirePV = new G4PVPlacement(wireRot, // rotation
131 wireOffset, // position
132 wireLV, // its logical volume
133 name + "_wire_pv", // its name
134 vac,
135 false, // no boolean operation
136 0, // copy number
139}
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.
Definition: BDSBeamPipe.hh:45
G4LogicalVolume * GetVacuumLogicalVolume() const
Access the vacuum volume to set fields and limits.
Definition: BDSBeamPipe.hh:65
G4ThreeVector InputFaceNormal() const
Accessor.
Definition: BDSBeamPipe.hh:73
G4ThreeVector OutputFaceNormal() const
Accessor.
Definition: BDSBeamPipe.hh:74
static BDSColours * Instance()
singleton pattern
Definition: BDSColours.cc:33
General exception with possible name of object and message.
Definition: BDSException.hh:35
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)
void RegisterSensitiveVolume(G4LogicalVolume *sensitiveVolume, BDSSDType sensitivityType)
virtual void BuildContainerLogicalVolume()
virtual void Build()
BDSWireScanner()=delete
Private default constructor to force the use of the supplied one.