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