BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSLaserWireNew.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 "BDSBeamPipe.hh"
20#include "BDSBeamPipeFactory.hh"
21#include "BDSAcceleratorComponent.hh"
22#include "BDSBeamPipeInfo.hh"
23#include "BDSColours.hh"
24#include "BDSDebug.hh"
25#include "BDSLaser.hh"
26#include "BDSLaserWireNew.hh"
27#include "BDSLogicalVolumeLaser.hh"
28#include "BDSMaterials.hh"
29#include "BDSUtilities.hh"
30#include "BDSWireScanner.hh"
31
32#include "globals.hh"
33#include "G4Hype.hh"
34#include "G4Tubs.hh"
35#include "G4IntersectionSolid.hh"
36#include "G4PVPlacement.hh"
37#include "G4ThreeVector.hh"
38#include "G4TwoVector.hh"
39#include "G4VisAttributes.hh"
40#include "BDSException.hh"
41
43 G4double lengthIn,
44 BDSBeamPipeInfo* beamPipeInfoIn,
45 BDSLaser* laserIn,
46 G4double wireDiameterIn,
47 G4double wireLengthIn,
48 G4double wireAngleIn,
49 G4double wireLongitudinalAngleIn,
50 G4ThreeVector wireOffsetIn,
51 G4Colour* wireColourIn):
52 BDSAcceleratorComponent(nameIn, lengthIn,0, "laserwire", beamPipeInfoIn),
53 laser(laserIn),
54 wireDiameter(wireDiameterIn),
55 wireLength(wireLengthIn),
56 wireAngle(wireAngleIn),
57 wireLongitudinalAngle(wireLongitudinalAngleIn),
58 wireOffset(wireOffsetIn),
59 wireColour(wireColourIn)
60
61{
62 wireMaterial = BDSMaterials::Instance()->GetMaterial("LaserVac");
63
64 if (wireDiameter <= 0)
65 {throw BDSException(__METHOD_NAME__,"W0 or Sigma0 in element " + name +" must be greater than 0.");}
66
67 if (wireLength <= 0)
68 {throw BDSException(__METHOD_NAME__,"wireLength in element " + name +" must be greater than 0.");}
69
70 if (wireLongitudinalAngle > CLHEP::halfpi && wireLongitudinalAngle < -1.0*CLHEP::halfpi)
71 {throw BDSException(__METHOD_NAME__,"laserOffsetPhi in element " + name +" must be between -pi/2 and pi/2.");}
72
73 if(wireAngle < CLHEP::pi && wireAngle < -1.0*CLHEP::pi)
74 {throw BDSException(__METHOD_NAME__,"laserOffsetTheta in element " + name +" must be between 0 and two pi.");}
75
76 // check whether the beam pipe will fit transversely (ignores presumably very small
77 // wire diameter). work out end points off wire including length and offset in x,y.
78 G4TwoVector offsetXY = G4TwoVector(wireOffset.x(), wireOffset.y());
79 G4TwoVector tipTop = G4TwoVector(0, 0.5*wireLength);
80 tipTop.rotate(wireAngle);
81 G4TwoVector tipBot = G4TwoVector(tipTop);
82 tipBot.rotate(CLHEP::pi);
83 tipTop += offsetXY;
84 tipBot += offsetXY;
85
86 if (!wireColour)
87 {wireColour = BDSColours::Instance()->GetColour("wirescanner");}
88}
89
90BDSLaserWireNew::~BDSLaserWireNew()
91{
92 delete laser;
93}
94
96{
98 BDSBeamPipe *pipe = factory->CreateBeamPipe(name + "_beampipe",
101 RegisterDaughter(pipe);
102
103 // make the beam pipe container, this object's container
104 containerLogicalVolume = pipe->GetContainerLogicalVolume();
105 containerSolid = pipe->GetContainerSolid();
106
107 // register vacuum volume (for biasing)
109
110 // update extents
111 InheritExtents(pipe);
112
113 // update faces
116}
117
119{
121
122 G4VSolid* wire = BuildHyperbolicWireSolid();
123 G4LogicalVolume* wireLV = BuildWireLV(wire);
124
125 // visualisation attributes
126 G4VisAttributes* wireVisAttr = new G4VisAttributes(*wireColour);
127 wireLV->SetVisAttributes(wireVisAttr);
128 RegisterVisAttributes(wireVisAttr);
129 // placement
130
131 G4RotationMatrix* placementWireRot = new G4RotationMatrix();
132
133 placementWireRot->rotateX(wireLongitudinalAngle);
134 // want to rotate about unit Z but this has now changed
135 placementWireRot->rotateY(CLHEP::pi-wireAngle);
136 placementWireRot->rotateZ(0);
137 placementWireRot->invert();
138 G4LogicalVolume* vac = *(GetAcceleratorVacuumLogicalVolumes().begin()); // take the first one
139 G4PVPlacement* wirePV = new G4PVPlacement(placementWireRot, // rotation
140 wireOffset, // position
141 wireLV, // its logical volume
142 name + "_wire_pv", // its name
143 vac,
144 false, // no boolean operation
145 0, // copy number
147
148
149 RegisterPhysicalVolume(wirePV);
150}
151
152G4VSolid* BDSLaserWireNew::BuildHyperbolicWireSolid()
153{
154 G4VSolid* laserwire = nullptr;
155 if (laser->IgnoreRayleighRange())
156 {
157 laserwire = new G4Tubs(name + "_laserwire_solid",
158 0,
159 wireDiameter * 0.5,
160 wireLength * 0.5,
161 0,
162 CLHEP::twopi);
163 }
164 else
165 {
166 laserwire = new G4Hype(name + "_laserwire_solid", //name
167 0, // inner radius
168 wireDiameter * 0.5, // outer radius
169 0, // inner stereo
170 laser->HyperbolicAngle(), // outer stereo
171 wireLength * 0.5);
172 }
173 RegisterSolid(laserwire);
174
175 G4ThreeVector unitLaserZ;
176 unitLaserZ.set(0,0,1);
177
178 // placement rotation
179 G4RotationMatrix* wireRot = new G4RotationMatrix();
180 // want to rotate about unit Z but this has now changed
181 wireRot->rotateX(wireLongitudinalAngle);
182 wireRot->rotateY(wireAngle);
183 //wireRot->rotateZ(0);
184 wireRot->invert();
185 RegisterRotationMatrix(wireRot);
186 wireColour->SetAlpha(0.5);
187
188
189 auto bpf = BDSBeamPipeFactory::Instance();
190 BDSBeamPipe* intersectionBP = bpf->CreateBeamPipeForVacuumIntersection(name + "_vacuum_intersection",
193 G4VSolid* vacuumSolid = intersectionBP->GetContainerSolid();
194 // do intersection with vacuumSolid
195 RegisterSolid(vacuumSolid);
196
197 G4VSolid* lasersolid = new G4IntersectionSolid(name + "_laserwire_solid",laserwire,vacuumSolid,wireRot,wireOffset);
198
199 RegisterSolid(lasersolid);
200
201 return lasersolid;
202}
203
204
205G4LogicalVolume* BDSLaserWireNew::BuildWireLV(G4VSolid* solid)
206{
208 wireMaterial,
209 name + "_laserwire_lv",
210 laser);
211 RegisterLogicalVolume(wireLV);
212 return wireLV;
213}
214
215
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.
BDSBeamPipeInfo * GetBeamPipeInfo() const
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()
BDSLaserWireNew()=delete
Private default constructor to force the use of the supplied one.
virtual void Build()
Class to provide laser intensity at any point.
Definition BDSLaser.hh:36
G4bool IgnoreRayleighRange() const
Accessor.
Definition BDSLaser.hh:74
Extended logical volume with laser definition.
static BDSMaterials * Instance()
Singleton pattern access.
G4Material * GetMaterial(G4String material) const
Get material by name.