Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/advanced/hadrontherapy/src/LaserDrivenBeamLine.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 // Hadrontherapy advanced example for Geant4
 27 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
 28 
 29 #include "globals.hh"
 30 #include "G4SystemOfUnits.hh"
 31 #include "G4Box.hh"
 32 #include "G4Tubs.hh"
 33 #include "G4Sphere.hh"
 34 #include "G4NistManager.hh"
 35 #include "G4NistElementBuilder.hh"
 36 #include "G4VisAttributes.hh"
 37 #include "G4Colour.hh"
 38 #include "G4RunManager.hh"
 39 #include "G4LogicalVolume.hh"
 40 #include "G4PVPlacement.hh"
 41 #include "G4RotationMatrix.hh"
 42 #include "HadrontherapyDetectorConstruction.hh"
 43 #include "LaserDrivenBeamLine.hh"
 44 #include "LaserDrivenBeamLineMessenger.hh"
 45 //
 46 #include "G4PhysicalConstants.hh"
 47 #include "G4ThreeVector.hh"
 48 #include "G4Material.hh"
 49 //
 50 #include "G4FieldManager.hh"
 51 #include "G4MagIntegratorStepper.hh"
 52 #include "G4Mag_UsualEqRhs.hh"
 53 #include "G4ExplicitEuler.hh"
 54 #include "G4ChordFinder.hh"
 55 //#include "G4TransportationManager.hh"
 56 #include "G4EqMagElectricField.hh"
 57 #include "G4UniformMagField.hh"
 58 #include "G4PropagatorInField.hh"
 59 #include "G4VisCommandsViewer.hh"
 60 #include "G4UImanager.hh"
 61 #include "G4ExplicitEuler.hh"
 62 #include "G4ImplicitEuler.hh"
 63 #include "G4SimpleRunge.hh"
 64 #include "G4SimpleHeum.hh"
 65 #include "G4ClassicalRK4.hh"
 66 #include "G4HelixExplicitEuler.hh"
 67 #include "G4HelixImplicitEuler.hh"
 68 #include "G4HelixSimpleRunge.hh"
 69 #include "G4CashKarpRKF45.hh"
 70 #include "G4RKG3_Stepper.hh"
 71 #include "G4MagIntegratorDriver.hh"
 72 #include "G4SubtractionSolid.hh"
 73 
 74 //
 75 #include "G4UniformElectricField.hh"
 76 #include "G4ElectricField.hh"
 77 #include "HadrontherapyElectricTabulatedField3D.hh"
 78 
 79 #include "HadrontherapyMagneticField3D.hh"
 80 //
 81 //G4bool LaserDrivenBeamLine::doCalculation = false;
 82 /////////////////////////////////////////////////////////////////////////////
 83 LaserDrivenBeamLine::LaserDrivenBeamLine():
 84 hadrontherapydetectorconstruction(0), physicTreatmentRoom(0),
 85 PFirstTriplet(0),PSecondTriplet(0),PThirdTriplet(0),PFourthTriplet(0), physicFirstQuad(0),physicSecondQuad(0),physicThirdQuad(0),physicFourthQuad(0),
 86 solidExternalChamber(0),logicExternalChamber(0),physicExternalChamber(0),
 87 solidInternalChamber(0),logicInternalChamber(0),physicInternalChamber(0),
 88 solidCollimator(0),logicCollimator(0),physicCollimator(0),
 89 solidCollimatorHole(0),logicCollimatorHole(0),physicCollimatorHole(0),
 90 solidFinalCollimator(0), logicFinalCollimator(0),physicFinalCollimator(0),
 91 solidFinalCollimatorHole(0),logicFinalCollimatorHole(0),physicFinalCollimatorHole(0),
 92 solidExternalMagnet_1(0),logicExternalMagnet_1(0),physicExternalMagnet_1(0), physicExternalMagnet_1Down(0),
 93 solidMagnet_1(0),logicMagnet_1(0),physicMagnet_1Right(0),physicMagnet_1Left(0), solidExternalMagnet_2(0),logicExternalMagnet_2(0),
 94 physicExternalMagnet_2(0),physicExternalMagnet_2Down(0),solidMagnet_2(0),logicMagnet_2(0),physicMagnet_2Right(0),physicMagnet_2Left(0), solidExternalMagnet_3(0),logicExternalMagnet_3(0),physicExternalMagnet_3(0),physicExternalMagnet_3Down(0),
 95 solidMagnet_3(0),logicMagnet_3(0),physicMagnet_3Right(0),physicMagnet_3Left(0),
 96 solidExternalMagnet_4(0),logicExternalMagnet_4(0),physicExternalMagnet_4(0),physicExternalMagnet_4Down(0),
 97 solidMagnet_4(0),logicMagnet_4(0),physicMagnet_4Right(0),physicMagnet_4Left(0),
 98 solidExternalSlit(0), logicExternalSlit(0), physicExternalSlit(0),
 99 solidInternalSlit(0),logicInternalSlit(0),physicInternalSlit(0),
100 physicExitPipe(0),physicExitWindow(0),physicExithole(0),physicEntrancePipe(0),physicEntrancehole(0)
101 {
102     laserDrivenMessenger = new LaserDrivenBeamLineMessenger(this);
103     
104     //***************************** PW ***************************************
105     
106     static G4String ROGeometryName = "DetectorROGeometry";
107     RO = new HadrontherapyDetectorROGeometry(ROGeometryName);
108     
109     G4cout << "Going to register Parallel world...";
110     RegisterParallelWorld(RO);
111     G4cout << "... done" << G4endl;
112     //***************************** PW ***************************************
113 }
114 
115 /////////////////////////////////////////////////////////////////////////////
116 LaserDrivenBeamLine::~LaserDrivenBeamLine()
117 {
118     //delete laserDrivenMessenger;
119     delete hadrontherapydetectorconstruction;
120 }
121 
122 /////////////////////////////////////////////////////////////////////////////
123 G4VPhysicalVolume* LaserDrivenBeamLine::Construct()
124 {
125     // Sets default geometry and materials
126     SetDefaultDimensions();
127     
128     // Construct the energyselector (magnetic part and slit) and detector plane
129     ConstructLaserDrivenBeamLine();
130     
131     //***************************** PW ***************************************
132     if (!hadrontherapydetectorconstruction)
133         
134         //***************************** PW ***************************************
135         
136         // HadrontherapyDetectorConstruction builds ONLY the phantom and the detector with its associated ROGeometry
137         hadrontherapydetectorconstruction = new HadrontherapyDetectorConstruction(physicTreatmentRoom);
138     G4cout<<"HadrontherapyDetectorConstruction"<<G4endl;
139     //***************************** PW ***************************************
140     
141     hadrontherapydetectorconstruction->InitializeDetectorROGeometry(RO,hadrontherapydetectorconstruction->GetDetectorToWorldPosition());
142     
143     //***************************** PW ***************************************
144     return physicTreatmentRoom;
145 }
146 /////////////////////////////////////////////////////////////////////////////
147 void LaserDrivenBeamLine::SetDefaultDimensions()
148 {
149     ///////////////////////////////////////////////////////////////////////
150     // Definition of the colour sets
151     white = new G4VisAttributes( G4Colour(1.,1.,1., 0.2));
152     white -> SetVisibility(true);
153     white -> SetForceSolid(true);
154     white -> SetForceWireframe(true);
155     
156     blue = new G4VisAttributes(G4Colour(0. ,0. ,1.));
157     blue -> SetVisibility(true);
158     //blue -> SetForceSolid(true);
159     
160     gray = new G4VisAttributes( G4Colour(0.5, 0.5, 0.5, 0.5 ));
161     gray-> SetVisibility(true);
162     gray-> SetForceSolid(true);
163     
164     red = new G4VisAttributes(G4Colour(1. ,0. ,0., 0.2));
165     red-> SetVisibility(true);
166     red-> SetForceSolid(true);
167     //red -> SetForceWireframe(true);
168     
169     yellow = new G4VisAttributes(G4Colour(1., 1., 0., 0.2));
170     yellow-> SetVisibility(true);
171     yellow-> SetForceSolid(true);
172     
173     green = new G4VisAttributes( G4Colour(25/255. , 255/255. ,  25/255., 0.4));
174     green -> SetVisibility(true);
175     green -> SetForceWireframe(true);
176     green -> SetForceSolid(true);
177     
178     black = new G4VisAttributes( G4Colour(255/255. , 255/255.,  255/255.));
179     black -> SetVisibility(true);
180     black -> SetForceSolid(true);
181     
182     darkGreen = new G4VisAttributes( G4Colour(0/255. , 100/255. ,  0/255.));
183     darkGreen -> SetVisibility(true);
184     darkGreen -> SetForceSolid(true);
185     
186     darkOrange3 = new G4VisAttributes( G4Colour(205/255. , 102/255. ,  000/255., 0.7));
187     darkOrange3 -> SetVisibility(true);
188     darkOrange3 -> SetForceSolid(true);
189     
190     skyBlue = new G4VisAttributes( G4Colour(135/255. , 206/255. ,  235/255., 0.1));
191     skyBlue -> SetVisibility(true);
192     skyBlue -> SetForceSolid(true);
193     
194     // DEFAULT DIMENSIONS AND POSITIONS ARE PROVIDED HERE.
195     /////////////////////// Exit Window ///////////////////////////////////////////////
196     G4double defaultInnerRadiusExitWindow=0. *mm;
197     InnerRadiusExitWindow=defaultInnerRadiusExitWindow;
198     
199     G4double defaultExternalRadiusExitWindow=55*mm;
200     ExternalRadiusExitWindow=defaultExternalRadiusExitWindow;
201     
202     G4double defaultExitWindowThickness=25 *um;
203     ExitWindowThickness=defaultExitWindowThickness;
204     
205     G4double defaultExitWindowXPosition=-ExitWindowThickness/2.;
206     ExitWindowXPosition=defaultExitWindowXPosition;
207     
208     G4double defaultExitWindowYPosition=0.;
209     ExitWindowYPosition=defaultExitWindowYPosition;
210     
211     G4double defaultExitWindowZPosition=0.0*mm;
212     ExitWindowZPosition=defaultExitWindowZPosition;
213     
214     G4double defaultStartAngleExitWindow = 0.0 *deg;
215     startAngleExitWindow = defaultStartAngleExitWindow;
216     
217     G4double defaultSpanningAngleExitWindow = 360.*deg;
218     spanningAngleExitWindow = defaultSpanningAngleExitWindow;
219     ////////////////////////////// Exit pipe ////////////////////////////////
220     G4double defaultExitPipeheight=105. *mm;
221     ExitPipeheight=defaultExitPipeheight;
222     
223     G4double defaultInnerRadiusExitPipe=50. *mm;
224     InnerRadiusExitPipe=defaultInnerRadiusExitPipe;
225     
226     G4double defaultExternalRadiusExitPipe=55 *mm;
227     ExternalRadiusExitPipe=defaultExternalRadiusExitPipe;
228     
229     G4double defaultExitPipeXPosition=-ExitPipeheight/2-ExitWindowThickness;
230     ExitPipeXPosition=defaultExitPipeXPosition;
231     
232     G4double defaultExitPipeYPosition=0;
233     ExitPipeYPosition=defaultExitPipeYPosition;
234     
235     G4double defaultExitPipeZPosition=0.0*mm;
236     ExitPipeZPosition=defaultExitPipeZPosition;
237     
238     G4double defaultStartAngleExitPipe = 0.0 *deg;
239     startAngleExitPipe = defaultStartAngleExitPipe;
240     
241     G4double defaultSpanningAngleExitPipe = 360.*deg;
242     spanningAngleExitPipe = defaultSpanningAngleExitPipe;
243     //////////////////////////////////////////////// Vacuum chamber //////////////////////////////
244     G4double defaultExternalChamberXSize = 79.6*cm;
245     externalChamberXSize = defaultExternalChamberXSize;
246     
247     G4double defaultExternalChamberYSize = 50. *cm;
248     externalChamberYSize = defaultExternalChamberYSize;
249     
250     G4double defaultExternalChamberZSize = 50. *cm;
251     externalChamberZSize = defaultExternalChamberZSize;
252     
253     G4double defaultExternalChamberXPosition = -(externalChamberXSize/2.+ExitPipeheight/2.)+ ExitPipeXPosition;
254     externalChamberXPosition = defaultExternalChamberXPosition;
255     
256     G4double defaultExternalChamberYPosition = 0.0 *mm;
257     externalChamberYPosition = defaultExternalChamberYPosition;
258     
259     G4double defaultExternalChamberZPosition = 0.0 *mm;
260     externalChamberZPosition = defaultExternalChamberZPosition;
261     
262     // Defaults of the internal chamber dimensions
263     // The position of its center is in the center
264     // of the internal chamber while the dimension are
265     // authomatically calculated respect to the external chamber ones
266     G4double defaultVaccumChamberWallThickness=5 *mm;
267     VaccumChamberWallThickness=defaultVaccumChamberWallThickness;
268     
269     G4double defaultInternalChamberXSize =externalChamberXSize - 2*VaccumChamberWallThickness;
270     internalChamberXSize = defaultInternalChamberXSize;
271     
272     G4double defaultInternalChamberYSize =externalChamberYSize - 2*VaccumChamberWallThickness;
273     internalChamberYSize = defaultInternalChamberYSize;
274     
275     G4double defaultInternalChamberZSize = externalChamberZSize - 2*VaccumChamberWallThickness;
276     internalChamberZSize = defaultInternalChamberZSize;
277     /////////////////////// Exit hole in vessel ///////////////////////////////////////////////
278     G4double defaultInnerRadiusExithole=0.*mm;
279     InnerRadiusExithole=defaultInnerRadiusExithole;
280     
281     G4double defaultExternalRadiusExithole=50.*mm;
282     ExternalRadiusExithole=defaultExternalRadiusExithole;
283     
284     G4double defaultExitholeThickness=VaccumChamberWallThickness;
285     ExitholeThickness=defaultExitholeThickness;
286     
287     G4double defaultExitholeXPosition=(externalChamberXSize/2.-ExitholeThickness/2.);
288     ExitholeXPosition=defaultExitholeXPosition;
289     
290     G4double defaultExitholeYPosition=0.;
291     ExitholeYPosition=defaultExitholeYPosition;
292     
293     G4double defaultExitholeZPosition=0.*mm;
294     ExitholeZPosition=defaultExitholeZPosition;
295     
296     G4double defaultStartAngleExithole = 0.0 *deg;
297     startAngleExithole= defaultStartAngleExithole;
298     
299     G4double defaultSpanningAngleExithole = 360.*deg;
300     spanningAngleExithole = defaultSpanningAngleExithole;
301     /////////////////////////////////Final collimator //////////////////////////////
302     // The Final Collimator is located after  the 4th magnet
303     G4double defaultExitholeToFinalCollimator=70 *mm;
304     ExitholeToFinalCollimator=defaultExitholeToFinalCollimator;
305     
306     defaultInnerRadiusFinalCollimator = 0.0 *mm;
307     innerRadiusFinalCollimator = defaultInnerRadiusFinalCollimator;
308     
309     defaultOuterRadiusFinalCollimator = 2.50 *mm;
310     outerRadiusFinalCollimator = defaultOuterRadiusFinalCollimator;
311     
312     defaultFinalCollimatorThickness = 3.0 *mm;
313     FinalCollimatorThickness = defaultFinalCollimatorThickness;
314     
315     defaultStartAngleFinalCollimator = 0.0 *deg;
316     startAngleFinalCollimator = defaultStartAngleFinalCollimator;
317     
318     defaultSpanningAngleFinalCollimator = 360.*deg;
319     spanningAngleFinalCollimator = defaultSpanningAngleFinalCollimator;
320     
321     defaultFinalCollimatorXPosition = internalChamberXSize/2.-ExitholeToFinalCollimator-FinalCollimatorThickness/2.;
322     collimatorFinalBox_XPosition=defaultFinalCollimatorXPosition;
323     FinalcollimatorXPosition = 0.0*mm; //HOLE IN THE FINAL COLLIMATOR
324     
325     defaultFinalCollimatorYPosition = 0.0*mm;
326     collimatorFinalBox_YPosition=defaultFinalCollimatorYPosition;
327     FinalcollimatorYPosition = defaultFinalCollimatorYPosition;
328     
329     defaultFinalCollimatorZPosition = 0.0*mm;
330     collimatorFinalBox_ZPosition=0.0*mm;
331     FinalcollimatorZPosition =defaultFinalCollimatorZPosition;
332     
333     defaultThicknessCollimator =3.0 *mm;
334     collimatorFinalBoxXSize=defaultFinalCollimatorThickness;
335     collimatorFinalBoxYSize=82.0*mm;
336     collimatorFinalBoxZSize=210.0*mm;
337     //////////////////ooooooooooOOOOOOOO000000000000OOOOOOOOOOOOooooooooooo/////////////////
338     
339     //Magnet characteristics
340     G4double defaultExternalMagnet_XSize = 88.0*mm;
341     G4double defaultExternalMagnet_YSizeTotal=87.*mm;
342     G4double defaultInternalMagnet_YSize = 10. *mm;
343     G4double defaultExternalMagnet_YSize =(defaultExternalMagnet_YSizeTotal-defaultInternalMagnet_YSize)/2.;
344     G4double defaultExternalMagnet_ZSize = 104 *mm;
345     
346     G4double defaultExternalMagnet_YPosition =defaultInternalMagnet_YSize/2.+defaultExternalMagnet_YSize/2.;
347     G4double defaultExternalMagnet_ZPosition = 0.0 *mm;
348     
349     G4double defaultMagnet_XSize=defaultExternalMagnet_XSize;
350     G4double defaultMagnet_YSize=defaultExternalMagnet_YSizeTotal;
351     G4double defaultMagnet_ZSize=19*mm;
352     
353     // Defaults of the external part of the magnet 4:
354     G4double defaultFinalCollimatorToMagnet4=25.*mm;
355     FinalCollimatorToMagnet4=defaultFinalCollimatorToMagnet4;
356     
357     externalMagnet_4XSize = defaultExternalMagnet_XSize;
358     externalMagnet_4YSize = defaultExternalMagnet_YSize;
359     externalMagnet_4ZSize = defaultExternalMagnet_ZSize;
360     
361     Magnet_4XSize=defaultMagnet_XSize;
362     Magnet_4YSize=defaultMagnet_YSize;
363     Magnet_4ZSize=defaultMagnet_ZSize;
364     
365     G4double defaultExternalMagnet_4XPosition = -(FinalCollimatorThickness/2.+FinalCollimatorToMagnet4+defaultExternalMagnet_XSize/2.)+ collimatorFinalBox_XPosition;
366     externalMagnet_4XPosition = defaultExternalMagnet_4XPosition;
367     
368     externalMagnet_4YPosition = defaultExternalMagnet_YPosition;
369     externalMagnet_4ZPosition = defaultExternalMagnet_ZPosition;
370     
371     Magnet_4XPosition=externalMagnet_4XPosition;
372     Magnet_4YPosition=0.0*mm;
373     Magnet_4ZPosition=(defaultExternalMagnet_ZSize+defaultMagnet_ZSize)/2.;
374     //////////////////ooooooooooOOOOOOOO000000000000OOOOOOOOOOOOooooooooooo/////////////////
375     // Defaults of the external part of the magnet 3:
376     externalMagnet_3XSize = defaultExternalMagnet_XSize;
377     externalMagnet_3YSize = defaultExternalMagnet_YSize;
378     externalMagnet_3ZSize = defaultExternalMagnet_ZSize;
379     
380     Magnet_3XSize=defaultMagnet_XSize;
381     Magnet_3YSize=defaultMagnet_YSize;
382     Magnet_3ZSize=defaultMagnet_ZSize;
383     
384     G4double defaultMagnet4ToMagnet3=65.*mm; //85.*mm ANTONELLA
385     Magnet4ToMagnet3=defaultMagnet4ToMagnet3;
386     
387     G4double defaultExternalMagnet_3XPosition =-(Magnet4ToMagnet3+defaultExternalMagnet_XSize/2.+defaultExternalMagnet_XSize/2.)+externalMagnet_4XPosition;
388     externalMagnet_3XPosition = defaultExternalMagnet_3XPosition;
389     
390     externalMagnet_3YPosition =defaultExternalMagnet_YPosition;
391     externalMagnet_3ZPosition = defaultExternalMagnet_ZPosition;
392     
393     
394     Magnet_3XPosition=externalMagnet_3XPosition;
395     Magnet_3YPosition=0.0*mm;
396     Magnet_3ZPosition=(defaultExternalMagnet_ZSize+defaultMagnet_ZSize)/2.;
397     //////////////////ooooooooooOOOOOOOO000000000000OOOOOOOOOOOOooooooooooo/////////////////
398     // Defaults of the external part of the magnet 2:
399     externalMagnet_2XSize = defaultExternalMagnet_XSize;
400     externalMagnet_2YSize = defaultExternalMagnet_YSize;
401     externalMagnet_2ZSize = defaultExternalMagnet_ZSize;
402     
403     Magnet_2XSize=defaultMagnet_XSize;
404     Magnet_2YSize=defaultMagnet_YSize;
405     Magnet_2ZSize=defaultMagnet_ZSize;
406     
407     G4double defaultMagnet3ToMagnet2=10 *mm;
408     Magnet3ToMagnet2=defaultMagnet3ToMagnet2;
409     
410     G4double defaultExternalMagnet_2XPosition =-(Magnet3ToMagnet2+defaultExternalMagnet_XSize/2.+defaultExternalMagnet_XSize/2.)+externalMagnet_3XPosition;
411     externalMagnet_2XPosition = defaultExternalMagnet_2XPosition;
412     
413     externalMagnet_2YPosition = defaultExternalMagnet_YPosition;
414     externalMagnet_2ZPosition = defaultExternalMagnet_ZPosition;
415     
416     Magnet_2XPosition=externalMagnet_2XPosition;
417     Magnet_2YPosition=0.0*mm;
418     Magnet_2ZPosition=(defaultExternalMagnet_ZSize+defaultMagnet_ZSize)/2.;
419     //////////////////ooooooooooOOOOOOOO000000000000OOOOOOOOOOOOooooooooooo/////////////////
420     // Defaults of the external part of the magnet 1:
421     externalMagnet_1XSize=defaultExternalMagnet_XSize;
422     externalMagnet_1YSize = defaultExternalMagnet_YSize;
423     externalMagnet_1ZSize = defaultExternalMagnet_ZSize;
424     
425     Magnet_1XSize=defaultMagnet_XSize;
426     Magnet_1YSize=defaultMagnet_YSize;
427     Magnet_1ZSize=defaultMagnet_ZSize;
428     
429     G4double defaultMagnet2ToMagnet1=85 *mm;
430     Magnet2ToMagnet1=defaultMagnet2ToMagnet1;
431     
432     G4double defaultExternalMagnet_1XPosition = -(Magnet2ToMagnet1+defaultExternalMagnet_XSize/2.+defaultExternalMagnet_XSize/2.)+externalMagnet_2XPosition;
433     externalMagnet_1XPosition = defaultExternalMagnet_1XPosition;
434     
435     externalMagnet_1YPosition = defaultExternalMagnet_YPosition;
436     externalMagnet_1ZPosition = defaultExternalMagnet_ZPosition;
437     
438     Magnet_1XPosition=defaultExternalMagnet_1XPosition;
439     Magnet_1YPosition=0.0*mm;
440     Magnet_1ZPosition=(defaultExternalMagnet_ZSize+defaultMagnet_ZSize)/2.;
441     
442     // Defaults of the external part of the Slit
443     G4double defaultExternalSlitXSize = 8.0 *mm;
444     externalSlitXSize = defaultExternalSlitXSize;
445     
446     G4double defaultExternalSlitYSize = 82. *mm;
447     externalSlitYSize = defaultExternalSlitYSize;
448     
449     G4double defaultExternalSlitZSize = 210. *mm;
450     externalSlitZSize = defaultExternalSlitZSize;
451     
452     G4double defaultExternalSlitXPosition = -(Magnet3ToMagnet2/2.+defaultExternalMagnet_XSize/2.)+externalMagnet_3XPosition;
453     externalSlitXPosition = defaultExternalSlitXPosition;
454     
455     G4double defaultExternalSlitYPosition = 0.0 *mm;
456     externalSlitYPosition = defaultExternalSlitYPosition;
457     
458     G4double defaultExternalSlitZPosition = 0.0 *mm;
459     externalSlitZPosition = defaultExternalSlitZPosition;
460     
461     // Defaults of the internal part of the Slit:
462     internalSlitXSize = defaultExternalSlitXSize;
463     
464     G4double defaultInternalSlitYSize = 3 *mm;
465     internalSlitYSize = defaultInternalSlitYSize;
466     
467     G4double defaultInternalSlitZSize = 3 *mm;
468     internalSlitZSize = defaultInternalSlitZSize;
469     
470     G4double defaultInternalSlitXPosition = 0.0 *mm;
471     internalSlitXPosition = defaultInternalSlitXPosition;
472     
473     G4double defaultInternalSlitYPosition = 0.0 *mm;
474     internalSlitYPosition = defaultInternalSlitYPosition;
475     
476     G4double defaultInternalSlitZPosition = 40.0 *mm;
477     internalSlitZPosition = defaultInternalSlitZPosition;
478     
479     // Defaults of the particle collimator (First collimator).
480     // The Collimator should be located before the 1st magnet
481     //
482     defaultInnerRadiusCollimator = 0.0 *mm;
483     innerRadiusCollimator = defaultInnerRadiusCollimator;
484     
485     defaultOuterRadiusCollimator = 2.5 *mm;
486     outerRadiusCollimator = defaultOuterRadiusCollimator;
487     
488     thicknessCollimator = defaultThicknessCollimator;
489     
490     defaultStartAngleCollimator = 0.0 *deg;
491     startAngleCollimator = defaultStartAngleCollimator;
492     
493     defaultSpanningAngleCollimator = 360.*deg;
494     spanningAngleCollimator = defaultSpanningAngleCollimator;
495     
496     G4double defultMagnet1ToFirstCollimator=25.*mm;
497     Magnet1ToFirstCollimator=defultMagnet1ToFirstCollimator;
498     
499     defaultCollimatorXPosition = -(thicknessCollimator/2.+Magnet1ToFirstCollimator+defaultExternalMagnet_XSize/2.)+externalMagnet_1XPosition;
500     collimatorBox_XPosition=defaultCollimatorXPosition;
501     collimatorXPosition = 0.0*mm;
502     
503     defaultCollimatorYPosition = 0.0*mm;
504     collimatorBox_YPosition=defaultCollimatorYPosition;
505     collimatorYPosition = 0.0*mm;
506     
507     defaultCollimatorZPosition = 0.0*mm;
508     collimatorBox_ZPosition=defaultCollimatorZPosition;
509     collimatorZPosition = 0.*mm;
510     
511     collimatorBoxYSize=82.0* mm;
512     collimatorBoxZSize=210.0* mm;
513     
514     //////////////////// Entrance Hole //////////////////////////////////
515     G4double defaultInnerRadiusEntrancehole=0. *mm;
516     InnerRadiusEntrancehole=defaultInnerRadiusEntrancehole;
517     
518     G4double defaultExternalRadiusEntrancehole=50.*mm;
519     ExternalRadiusEntrancehole=defaultExternalRadiusEntrancehole;
520     
521     G4double defaultEntranceholeThickness=VaccumChamberWallThickness;
522     EntranceholeThickness=defaultEntranceholeThickness;
523     
524     G4double defaultEntranceholeXPosition=-(externalChamberXSize/2.-EntranceholeThickness/2.);
525     EntranceholeXPosition=defaultEntranceholeXPosition;
526     
527     G4double defaultEntranceholeQuadXPosition=+(externalChamberXSize/2.-EntranceholeThickness/2.);
528     EntranceholeQuadXPosition=defaultEntranceholeQuadXPosition;
529     
530     G4double defaultEntranceholeYPosition=0.;
531     EntranceholeYPosition=defaultEntranceholeYPosition;
532     
533     G4double defaultEntranceholeZPosition=0.0*mm;
534     EntranceholeZPosition=defaultEntranceholeZPosition;
535     
536     G4double defaultStartAngleEntrancehole= 0.0 *deg;
537     startAngleEntrancehole= defaultStartAngleEntrancehole;
538     
539     G4double defaultSpanningAngleEntrancehole= 360.*deg;
540     spanningAngleEntrancehole=defaultSpanningAngleEntrancehole;
541     
542     ///////////////// Entrance Pipe/////////////////////////////////////////////
543     
544     G4double defaultEntrancePipeheight=105. *mm;
545     EntrancePipeheight=defaultEntrancePipeheight;
546     
547     G4double defaultInnerRadiusEntrancePipe=50. *mm;
548     InnerRadiusEntrancePipe=defaultInnerRadiusEntrancePipe;
549     
550     G4double defaultExternalRadiusEntrancePipe=55 *mm;
551     ExternalRadiusEntrancePipe=defaultExternalRadiusEntrancePipe;
552     
553     G4double defaultEntrancePipeXPosition=-EntrancePipeheight/2-externalChamberXSize/2+externalChamberXPosition;
554     EntrancePipeXPosition=defaultEntrancePipeXPosition;
555     
556     G4double defaultEntrancePipeYPosition=0;
557     EntrancePipeYPosition=defaultEntrancePipeYPosition;
558     
559     G4double defaultEntrancePipeZPosition=0.0*mm;
560     EntrancePipeZPosition=defaultEntrancePipeZPosition;
561     
562     G4double defaultStartAngleEntrancePipe= 0.0 *deg;
563     startAngleEntrancePipe= defaultStartAngleEntrancePipe;
564     
565     G4double defaultSpanningAngleEntrancePipe= 360.*deg;
566     spanningAngleEntrancePipe=defaultSpanningAngleEntrancePipe;
567     
568     /////////////////////////////////////Quadrupole//////////////////////////////////
569     G4double defaultQuadChamberWallPosX=-(externalChamberXSize/2.)-EntrancePipeheight/2.+EntrancePipeXPosition;
570     QuadChamberWallPosX=defaultQuadChamberWallPosX;
571     G4double defaultQuadChamberWallPosY=0.0*cm;
572     QuadChamberWallPosY=defaultQuadChamberWallPosY;
573     G4double defaultQuadChamberWallPosZ=0.0*cm;
574     QuadChamberWallPosZ=defaultQuadChamberWallPosZ;
575     
576     G4double defaultInnerRadiusQuad=10.0*mm;
577     InnerRadiusQuad=defaultInnerRadiusQuad;
578     
579     G4double defaultInnerRadiusTriplet=0.0*mm;
580     InnerRadiusTriplet=defaultInnerRadiusTriplet;
581     
582     G4double defaultExternalRadiusQuad=30.0*mm;
583     ExternalRadiusQuad=defaultExternalRadiusQuad;
584     
585     G4double defaultFirstQuadThickness=80.0*mm;
586     FirstQuadThickness=defaultFirstQuadThickness;
587     G4double defaultSecondQuadThickness=40.0*mm;
588     SecondQuadThickness=defaultSecondQuadThickness;
589     G4double defaultThirdQuadThickness=40.0*mm;
590     ThirdQuadThickness=defaultThirdQuadThickness;
591     G4double defaultFourthQuadThickness=80.0*mm;
592     FourthQuadThickness=defaultFourthQuadThickness;
593     
594     G4double defaultStartAngleQuad = 0.0 *deg;
595     startAngleQuad = defaultStartAngleQuad;
596     
597     G4double defaultSpanningAngleQuad = 360.*deg;
598     spanningAngleQuad = defaultSpanningAngleQuad;
599     
600     G4double distancefromQuadChamber=100.0*mm;
601     G4double defaultFourthQuadXPosition= internalChamberXSize/2.-distancefromQuadChamber-FourthQuadThickness/2.;
602     FourthQuadXPosition=defaultFourthQuadXPosition;
603     FourthQXPosition=0.0*mm;
604     
605     G4double distanceFQuadTQuad=100.0*mm;
606     G4double defaultThirdQuadXPosition=-ThirdQuadThickness/2.-distanceFQuadTQuad-FourthQuadThickness/2.+FourthQuadXPosition;
607     ThirdQuadXPosition=defaultThirdQuadXPosition;
608     ThirdQXPosition=0.0*mm;
609     
610     G4double distanceTQuadSQuad=100.0*mm;
611     G4double defaultSecondQuadXPosition=-SecondQuadThickness/2.-distanceTQuadSQuad-ThirdQuadThickness/2.+ThirdQuadXPosition;
612     SecondQuadXPosition=defaultSecondQuadXPosition;
613     SecondQXPosition=0.0*mm;
614     
615     G4double distanceSQuadFQuad=100.0*mm;
616     G4double defaultFirstQuadXPosition=-FirstQuadThickness/2.-distanceSQuadFQuad-SecondQuadThickness/2.+SecondQuadXPosition;
617     FirstQuadXPosition=defaultFirstQuadXPosition;
618     FirstQXPosition=0.0*mm;
619     
620     G4double defaultQuadYPosition=0.0*mm;
621     QuadYPosition=defaultQuadYPosition;
622     QYPosition=defaultQuadYPosition;
623     
624     G4double defaultQuadTZPosition= 0.*mm;
625     QuadZPosition=defaultQuadTZPosition;
626     G4double defaultQuadZPosition=0.0*mm;
627     QZPosition=defaultQuadZPosition;
628     
629     // DEFAULT DEFINITION OF THE MATERIALS
630     // All elements and compound definition follows the NIST database
631     
632     //ELEMENTS
633     G4bool isotopes = false;
634     G4Element* zincNist = G4NistManager::Instance()->FindOrBuildElement("Zn");
635     G4Element* copperNist = G4NistManager::Instance()->FindOrBuildElement("Cu");
636     
637     //COMPOUNDS
638     G4Material* ironNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe", isotopes);
639     G4Material* aluminiumNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
640     G4Material* kaptonNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON", isotopes);
641     //G4Material* waterNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER", isotopes);
642     G4Material* stainless_steelNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_STAINLESS-STEEL", isotopes);
643     
644     // Elements and compunds not pre-defined in Geant4
645     G4double d; // Density
646     G4int nComponents;// Number of components
647     G4double fractionmass; // Fraction in mass of an element in a material
648     d = 8.40*g/cm3;
649     nComponents = 2;
650     G4Material* brass = new G4Material("Brass", d, nComponents);
651     brass -> AddElement(zincNist, fractionmass = 30 *perCent);
652     brass -> AddElement(copperNist, fractionmass = 70 *perCent);
653     
654     G4double atomicNumber = 1.;
655     G4double massOfMole = 1.008*g/mole;
656     d = 1.e-25*g/cm3;
657     G4double temperature = 2.73*kelvin;
658     G4double pressure = 3.e-18*pascal;
659     G4Material* vacuum = new G4Material("interGalactic", atomicNumber,massOfMole, d, kStateGas,temperature, pressure);
660     
661     //***************************** PW ***************************************
662     
663     // DetectorROGeometry Material
664     new G4Material("dummyMat", 1., 1.*g/mole, 1.*g/cm3);
665     
666     //***************************** PW ***************************************
667     
668     // MATERIAL ASSIGNMENT
669     MotherMaterial=vacuum;
670     QuadMaterial=ironNist;
671     externalChamberMaterial = stainless_steelNist;
672     internalChamberMaterial = vacuum;
673     collimatorMaterial = aluminiumNist;
674     collimatorHoleMaterial=vacuum;
675     FinalcollimatorMaterial=aluminiumNist;
676     FinalcollimatorHoleMaterial=vacuum;
677     WindowMaterial=kaptonNist;
678     PipeMaterial=stainless_steelNist;
679     
680     externalMagnet_1Material = ironNist;
681     externalMagnet_2Material = ironNist;
682     externalMagnet_3Material = ironNist;
683     externalMagnet_4Material = ironNist;
684     
685     externalSlitMaterial = brass;
686     internalSlitMaterial =vacuum;
687     
688     //FC Material
689     
690     KaptonEntranceWindowMaterial=kaptonNist;
691     GuardRingMaterial=stainless_steelNist;
692     FaradayCupBottomMaterial=aluminiumNist;
693     CupMaterial=FaradayCupBottomMaterial;
694     MassRingMaterial=GuardRingMaterial;
695     
696 }
697 
698 /////////////////////////////////////////////////////////////////////////////
699 void LaserDrivenBeamLine::ConstructLaserDrivenBeamLine()
700 {
701     // -----------------------------
702     // Treatment room - World volume
703     //------------------------------
704     
705     const G4double worldX = 800.0 *cm;
706     const G4double worldY = 400.0 *cm;
707     const G4double worldZ = 400.0 *cm;
708     
709     solidTreatmentRoom = new G4Box("TreatmentRoom",
710                                    worldX,
711                                    worldY,
712                                    worldZ);
713     
714     logicTreatmentRoom = new G4LogicalVolume(solidTreatmentRoom,
715                                              MotherMaterial,
716                                              "logicTreatmentRoom",
717                                              0,
718                                              0,
719                                              0);
720     
721     physicTreatmentRoom = new G4PVPlacement(0,
722                                             G4ThreeVector(),
723                                             "physicalTreatmentRoom",
724                                             logicTreatmentRoom,
725                                             0,
726                                             false,
727                                             0);
728     
729     
730     // The treatment room is invisible in the Visualisation
731     logicTreatmentRoom -> SetVisAttributes (G4VisAttributes::GetInvisible());
732     
733     // The various components of the energyselector are constructed calling
734     // the following methods
735     
736     // This method constructs the chamber where the energyselector is located
737     EnergySelectorChamber();
738     // This method construct the exit window
739     ExitWindow();
740     // This method construct the exit pipe
741     ExitPipe();
742     // This method construct the exit hole
743     Exithole();
744     
745     // This method constructs a circular collimator of variable thickness and
746     // aperture. It is placed befor the magnet to collimate particles caming from the
747     // plasma;
748     Collimator();
749     
750     // This method constructs the magnet 1 and its associated magnetic field
751     Magnet_1();
752     
753     // This method constructs the magnet 2 and its associated magnetic field
754     Magnet_2();
755     
756     // This method constructs the magnet 3 and its associated magnetic field
757     Magnet_3();
758     
759     // This method constructs the magnet 4 and its associated magnetic field
760     Magnet_4();
761     
762     // The selection slit is a square hole moveable inside a metallic plate
763     Slit();
764     
765     FinalCollimator();
766     
767     // This method construct the quadrupoles
768     Quadrupole();
769     // This method construct the entrance hole
770     Entrancehole();
771     // This method construct the entrance pipe
772     EntrancePipe();
773     
774     FaradayCup();
775     
776 }
777 
778 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
779 
780 void LaserDrivenBeamLine::ConstructSDandField()
781 {
782     G4double minEps=1.0e-5;  //   Minimum & value for smallest steps
783     G4double maxEps=1.0e-4;
784     G4bool allLocal = true;
785     // G4int nvar = 8;  For pure magnetic field, the number of integration variables is the default!
786     
787     //....oooOO0OOooo..........ENERGY SELECTOR SYSTEM FIELD..........oooOO0OOooo....
788     if(logicInternalChamber){G4double xOffset =(internalChamberXSize/2.0)+externalSlitXPosition;
789         PurgMagField = new HadrontherapyMagneticField3D("field/ESSMagneticField.TABLE", xOffset);
790         pFieldMgr =new G4FieldManager();
791         pFieldMgr -> SetDetectorField(PurgMagField);
792         G4cout << "DeltaStep "<< pFieldMgr -> GetDeltaOneStep()/mm <<"mm" <<G4endl;
793         pFieldMgr -> CreateChordFinder(PurgMagField);
794         fEquation = new G4Mag_UsualEqRhs(PurgMagField);
795         fstepper = new G4ClassicalRK4(fEquation);
796         //////fstepper = new G4HelixImplicitEuler(fEquation);
797         pIntgrDriver = new G4MagInt_Driver(1*mm,fstepper,fstepper-> GetNumberOfVariables());
798         //the first parameter is the minimum step
799         pChordFinder = new G4ChordFinder(pIntgrDriver);
800         pFieldMgr->SetChordFinder(pChordFinder);
801         pFieldMgr->SetMinimumEpsilonStep(minEps);
802         pFieldMgr->SetMaximumEpsilonStep(maxEps);
803         pFieldMgr->SetDeltaOneStep(0.5e-3*mm);//default value of DeltaChord is 0.25 mm
804         logicInternalChamber -> SetFieldManager(pFieldMgr, allLocal);}
805     //....oooOO0OOooo..........QUADS FIELDS..........oooOO0OOooo....
806     //....oooOO0OOooo..........FOURTH QUAD FIELD..........oooOO0OOooo....
807     if(LFourthTriplet){G4double xOffsetFQ =-(QuadChamberWallPosX+FourthQuadXPosition);
808         PurgMagFieldQuadFourth = new HadrontherapyMagneticField3D("field/Quad80MagneticField.TABLE", xOffsetFQ);
809         pFieldMgrQuadFourth =  new G4FieldManager();
810         pFieldMgrQuadFourth -> SetDetectorField(PurgMagFieldQuadFourth);
811         
812         pFieldMgrQuadFourth -> CreateChordFinder(PurgMagFieldQuadFourth);
813         fEquationQuadFourth = new G4Mag_UsualEqRhs(PurgMagFieldQuadFourth);
814         fstepperQuadFourth = new G4ClassicalRK4(fEquationQuadFourth);
815         pIntgrDriverQuadFourth = new G4MagInt_Driver(1*mm,fstepperQuadFourth,fstepperQuadFourth-> GetNumberOfVariables());
816         //the first parameter is the minimum step
817         pChordFinderQuadFourth = new G4ChordFinder(pIntgrDriverQuadFourth);
818         pFieldMgrQuadFourth->SetChordFinder(pChordFinderQuadFourth);
819         pFieldMgrQuadFourth->SetMinimumEpsilonStep(minEps);
820         pFieldMgrQuadFourth->SetMaximumEpsilonStep(maxEps);
821         pFieldMgrQuadFourth->SetDeltaOneStep(0.5e-3*mm);//default value of DeltaChord is 0.25 mm
822         LFourthTriplet -> SetFieldManager(pFieldMgrQuadFourth, allLocal);}
823     //....oooOO0OOooo..........THIRD QUAD FIELD..........oooOO0OOooo....
824     if(LThirdTriplet){ G4double xOffsetTQ =-(QuadChamberWallPosX+ThirdQuadXPosition);
825         PurgMagFieldQuadThird = new HadrontherapyMagneticField3D("field/Quad40MagneticField.TABLE", xOffsetTQ);
826         pFieldMgrQuadThird =  new G4FieldManager();
827         pFieldMgrQuadThird -> SetDetectorField(PurgMagFieldQuadThird);
828         pFieldMgrQuadThird -> CreateChordFinder(PurgMagFieldQuadThird);
829         fEquationQuadThird = new G4Mag_UsualEqRhs(PurgMagFieldQuadThird);
830         fstepperQuadThird = new G4ClassicalRK4(fEquationQuadThird);
831         pIntgrDriverQuadThird = new G4MagInt_Driver(1*mm,fstepperQuadThird,fstepperQuadThird-> GetNumberOfVariables());
832         //the first parameter is the minimum step
833         pChordFinderQuadThird = new G4ChordFinder(pIntgrDriverQuadThird);
834         pFieldMgrQuadThird->SetChordFinder(pChordFinderQuadThird);
835         pFieldMgrQuadThird->SetMinimumEpsilonStep(minEps);
836         pFieldMgrQuadThird->SetMaximumEpsilonStep(maxEps);
837         pFieldMgrQuadThird->SetDeltaOneStep(0.5e-3*mm);//default value of DeltaChord is 0.25 mm
838         LThirdTriplet -> SetFieldManager(pFieldMgrQuadThird, allLocal);}
839     //....oooOO0OOooo..........SECOND QUAD FIELD..........oooOO0OOooo....
840     if(LSecondTriplet){G4double xOffsetSQ =-(QuadChamberWallPosX+SecondQuadXPosition);
841         PurgMagFieldQuadSecond = new HadrontherapyMagneticField3D("field/Quad40MagneticField.TABLE", xOffsetSQ);
842         pFieldMgrQuadSecond =  new G4FieldManager();
843         pFieldMgrQuadSecond -> SetDetectorField(PurgMagFieldQuadSecond);
844         pFieldMgrQuadSecond -> CreateChordFinder(PurgMagFieldQuadSecond);
845         fEquationQuadSecond = new G4Mag_UsualEqRhs(PurgMagFieldQuadSecond);
846         fstepperQuadSecond = new G4ClassicalRK4(fEquationQuadSecond);
847         pIntgrDriverQuadSecond = new G4MagInt_Driver(1*mm,fstepperQuadSecond,fstepperQuadSecond-> GetNumberOfVariables());
848         //the first parameter is the minimum step
849         pChordFinderQuadSecond = new G4ChordFinder(pIntgrDriverQuadSecond);
850         pFieldMgrQuadSecond->SetChordFinder(pChordFinderQuadSecond);
851         pFieldMgrQuadSecond->SetMinimumEpsilonStep(minEps);
852         pFieldMgrQuadSecond->SetMaximumEpsilonStep(maxEps);
853         pFieldMgrQuadSecond->SetDeltaOneStep(0.5e-3*mm);//default value of DeltaChord is 0.25 mm
854         LSecondTriplet -> SetFieldManager(pFieldMgrQuadSecond, allLocal);}
855     //....oooOO0OOooo..........FIRST QUAD FIELD..........oooOO0OOooo....
856     if(LFirstTriplet) {G4double xOffsetFirstQ =-(QuadChamberWallPosX+FirstQuadXPosition);
857         PurgMagFieldQuadFirst = new HadrontherapyMagneticField3D("field/Quad80MagneticField.TABLE", xOffsetFirstQ);
858         pFieldMgrQuadFirst =  new G4FieldManager();
859         pFieldMgrQuadFirst -> SetDetectorField(PurgMagFieldQuadFirst);
860         pFieldMgrQuadFirst -> CreateChordFinder(PurgMagFieldQuadFirst);
861         fEquationQuadFirst = new G4Mag_UsualEqRhs(PurgMagFieldQuadFirst);
862         fstepperQuadFirst = new G4ClassicalRK4(fEquationQuadFirst);
863         pIntgrDriverQuadFirst = new G4MagInt_Driver(1*mm,fstepperQuadFirst,fstepperQuadFirst-> GetNumberOfVariables());
864         //the first parameter is the minimum step
865         pChordFinderQuadFirst = new G4ChordFinder(pIntgrDriverQuadFirst);
866         pFieldMgrQuadFirst->SetChordFinder(pChordFinderQuadFirst);
867         pFieldMgrQuadFirst->SetMinimumEpsilonStep(minEps);
868         pFieldMgrQuadFirst->SetMaximumEpsilonStep(maxEps);
869         pFieldMgrQuadFirst->SetDeltaOneStep(0.5e-3*mm);//default value of DeltaChord is 0.25 mm
870         LFirstTriplet -> SetFieldManager(pFieldMgrQuadFirst, allLocal);}
871     //....oooOO0OOooo..........FARADAY CUP FIELD..........oooOO0OOooo....
872     if(logicVirtualMag) {G4double exOffset= -20*cm;
873         G4double eyOffset= 0*cm;
874         G4double ezOffset= 0*cm;
875         G4FieldManager *pEFieldmanager = new G4FieldManager();
876         G4ElectricField *ElectricField = new HadrontherapyElectricTabulatedField3D("field/ElectricFieldFC-600V.TABLE", exOffset, eyOffset, ezOffset);
877         // UNIFORM FIELD
878         // G4ElectroMagneticField* ElectricField = new G4UniformElectricField(G4ThreeVector(0.0, 10.0*volt/m, 0.0)); //G4UniformElectricField
879         // The following is only for global field in the whole geometry
880         //pEFieldmanager = G4TransportationManager::GetTransportationManager() -> GetFieldManager();
881         
882         const G4int nvarElectric=8;  // The Equation of motion for Electric (or combined Electric/Magnetic)
883         // field requires 8 integration variables
884         
885         G4EqMagElectricField *fLocalEquation = new G4EqMagElectricField(ElectricField);
886         G4MagIntegratorStepper* fLocalStepper = new G4ClassicalRK4(fLocalEquation, nvarElectric);
887         G4MagInt_Driver  *pIntgrDriver_E = new G4MagInt_Driver(0.02*mm, fLocalStepper, fLocalStepper -> GetNumberOfVariables() );
888         G4ChordFinder *fLocalChordFinder = new G4ChordFinder(pIntgrDriver_E);
889         pEFieldmanager -> SetDetectorField(ElectricField);
890         pEFieldmanager -> SetChordFinder(fLocalChordFinder);
891         //G4double deltainter=0.0001*mm;
892         //G4double missdist=0.1*mm;
893         //pEFieldmanager->SetDeltaIntersection(deltainter);
894         //fLocalChordFinder->SetDeltaChord(missdist);
895         pEFieldmanager->SetMinimumEpsilonStep(minEps);
896         pEFieldmanager->SetMaximumEpsilonStep(maxEps);
897         pEFieldmanager->SetDeltaOneStep( 0.5e-3 * mm );
898         //pEFieldmanager -> SetFieldChangesEnergy(true);
899         logicVirtualMag -> SetFieldManager(pEFieldmanager, allLocal);}
900     //....oooOO0OOooo....................oooOO0OOooo....
901     G4cout<<" //....oooOO0OOooo.......... FIELDS HAVE BEEN IMPLEMENTED..........oooOO0OOooo...."<<G4endl;
902     return;
903 }
904 
905 /////////////////////////////////////////////////////////////////////////////
906 void LaserDrivenBeamLine::FaradayCup()
907 {
908     /// FC sizes ///
909     
910     G4double InnerRadiusFC=25*mm;
911     G4double OuterRadiusFC=45*mm;
912     G4double MassRingThickness=5*mm;
913     G4double GuardRingThickness=180*mm;
914     G4double FaradayCupBottomThickness=120*mm;
915     G4double CupThickness=10*cm;
916     G4double KaptonEntranceWindowThickness=25*um;
917     
918     /// Virtual Volumes ///
919     
920     G4double VirtualWindowThickness=1.*um ;
921     G4double VirtualMiddleThickness= 1.*um ;
922     G4double VirtualBottomThickness= 1. *um ;
923     G4double VirtualOverBottomThickness=1. *um ;
924     G4double VirtualLateralLength=FaradayCupBottomThickness+CupThickness+VirtualBottomThickness;
925     
926     
927     //// Position ////
928     
929     G4double virtualMagPosX=31*cm;
930     G4double FC_XOffset=20*cm;
931     G4double KaptonEntranceWindowPosX=-virtualMagPosX+KaptonEntranceWindowThickness/2+FC_XOffset;
932     G4double MassRingPosX=KaptonEntranceWindowPosX+KaptonEntranceWindowThickness/2+MassRingThickness/2;
933     G4double VirtualWindowPosX=MassRingPosX+MassRingThickness/2+VirtualWindowThickness/2;
934     G4double GuardRingPosX=MassRingPosX+MassRingThickness/2+GuardRingThickness/2+2*mm;
935     G4double VirtualMiddlePosX=GuardRingPosX+GuardRingThickness/2+VirtualMiddleThickness/2;
936     G4double FaradayCupBottomPosX=GuardRingPosX+GuardRingThickness/2+FaradayCupBottomThickness/2+1*cm;
937     G4double VirtualBottomPosX=FaradayCupBottomPosX+FaradayCupBottomThickness/2+VirtualBottomThickness/2;
938     G4double CupPosX=VirtualBottomPosX+VirtualBottomThickness/2+CupThickness/2;
939     G4double VirtualOverBottomPosX=CupPosX+CupThickness/2+VirtualOverBottomThickness/2;
940     G4double VirtualLateralPosX=GuardRingPosX+GuardRingThickness/2+1*cm+(FaradayCupBottomThickness+CupThickness+VirtualBottomThickness)/2;
941     G4double phi = 90. *deg;
942     G4RotationMatrix rm;
943     rm.rotateY(phi);
944     
945     virtualMag= new G4Box("virtualMag", 31.*cm, 6*cm, 6*cm );
946     
947     logicVirtualMag= new G4LogicalVolume( virtualMag,
948                                          internalChamberMaterial,
949                                          "LVirtualMag",
950                                          0,0,0);
951     physicVirtualMag = new G4PVPlacement(0,
952                                          G4ThreeVector(virtualMagPosX, 0.*cm, 0*mm),
953                                          "PVirtualMag",
954                                          logicVirtualMag,
955                                          physicTreatmentRoom,
956                                          true, 0);
957     
958     
959     logicVirtualMag -> SetVisAttributes(blue);
960     
961     //// BeveledCylinder ////
962     
963     G4RotationMatrix *Rot= new G4RotationMatrix;
964     Rot->rotateX(14*deg);
965     G4ThreeVector trans(0.,22.5*mm,-15*mm);
966     Cylinder= new G4Tubs("cylinder",20*mm,22.5*mm,90*mm,0.,2*pi);
967     Box= new G4Box("Box",22.5*mm,22.5*mm,90*mm);
968     
969     G4SubtractionSolid* BeveledCylinder=new G4SubtractionSolid("Cylinder-Box",
970                                                                Cylinder,
971                                                                Box,
972                                                                Rot,
973                                                                trans);
974     
975     logicBeveledCylinder= new G4LogicalVolume                   (BeveledCylinder,
976                                                                  GuardRingMaterial,
977                                                                  "LBeveledCylinder",
978                                                                  0,0,0);
979     
980     physicBeveledCylinder =new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(GuardRingPosX,0,0)),
981                                              "physicBeveledCylinder",
982                                              logicBeveledCylinder,
983                                              physicVirtualMag,
984                                              true,0);
985     
986     logicBeveledCylinder->SetVisAttributes(green);
987     
988     
989     ///// KaptonEntranceWindow /////
990     
991     KaptonEntranceWindow= new G4Tubs("KaptonEntranceWindow",
992                                      0,
993                                      OuterRadiusFC,
994                                      KaptonEntranceWindowThickness/2,
995                                      0*deg,360*deg);
996     
997     logicKaptonEntranceWindow=new G4LogicalVolume(          KaptonEntranceWindow,
998                                                   // internalChamberMaterial, for track control
999                                                   KaptonEntranceWindowMaterial,
1000                                                   "LKaptonEntranceWindow",
1001                                                   0,0,0);
1002     
1003     physicKaptonEntranceWindow=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(KaptonEntranceWindowPosX,0,0)),
1004                                                  "PhysicEntranceWindow",
1005                                                  logicKaptonEntranceWindow,
1006                                                  physicVirtualMag,true,0);
1007     logicKaptonEntranceWindow -> SetVisAttributes(gray);
1008     
1009     ////// MassRing /////
1010     
1011     MassRing=new G4Tubs ("MassRing",
1012                          InnerRadiusFC,
1013                          OuterRadiusFC,
1014                          MassRingThickness/2,
1015                          0*deg,360*deg);
1016     
1017     logicMassRing=new G4LogicalVolume(                      MassRing,
1018                                       MassRingMaterial,
1019                                       "logicMassRing",
1020                                       0,0,0);
1021     
1022     physicMassRing=new G4PVPlacement(                       G4Transform3D(rm,G4ThreeVector(MassRingPosX,0,0)),
1023                                      
1024                                      "PhysicMassRing",logicMassRing,
1025                                      
1026                                      physicVirtualMag,
1027                                      true,0);
1028     logicMassRing -> SetVisAttributes(green);
1029     
1030     
1031     
1032     
1033     ///// VirtualWindow /////
1034     
1035     
1036     VirtualWindow=new G4Tubs("VirtualWindow",
1037                              0,
1038                              OuterRadiusFC,
1039                              VirtualWindowThickness/2,
1040                              0*deg,360*deg);
1041     
1042     logicVirtualWindow=new G4LogicalVolume(                 VirtualWindow,
1043                                            internalChamberMaterial,
1044                                            "logicVirtualWindow",
1045                                            0,0,0);
1046     
1047     physicVirtualWindow=new G4PVPlacement(                   G4Transform3D(rm,G4ThreeVector(VirtualWindowPosX,0,0)),
1048                                           
1049                                           "PhysicVirtualWindow",
1050                                           logicVirtualWindow,
1051                                           physicVirtualMag,
1052                                           true,0);
1053     logicVirtualWindow->SetVisAttributes (G4VisAttributes::GetInvisible());
1054     
1055     ///// GuardRing /////
1056     
1057     GuardRing=new G4Tubs ("GuardRing",
1058                           InnerRadiusFC,
1059                           OuterRadiusFC,
1060                           GuardRingThickness/2,
1061                           0*deg,360*deg);
1062     
1063     logicGuardRing=new G4LogicalVolume(                      GuardRing,
1064                                        GuardRingMaterial,
1065                                        "logicGuardRing",
1066                                        0,0,0);
1067     
1068     physicGuardRing=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(GuardRingPosX,0,0)),
1069                                       
1070                                       "PhysicGuardRing", logicGuardRing,
1071                                       
1072                                       physicVirtualMag,
1073                                       true,0);
1074     logicGuardRing -> SetVisAttributes(red);
1075     
1076     
1077     /////VirtualMiddle /////
1078     
1079     
1080     VirtualMiddle=new G4Tubs ("VirtualMiddle",
1081                               0,
1082                               OuterRadiusFC,
1083                               VirtualMiddleThickness/2,
1084                               0*deg,360*deg);
1085     
1086     logicVirtualMiddle=new G4LogicalVolume(                      VirtualMiddle,
1087                                            internalChamberMaterial,
1088                                            "logicVirtualMiddle",
1089                                            0,0,0);
1090     
1091     physicVirtualMiddle=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualMiddlePosX,0,0)),
1092                                           
1093                                           "PhysicVirtualMiddle", logicVirtualMiddle,
1094                                           
1095                                           physicVirtualMag,
1096                                           true,0);
1097     
1098     logicVirtualMiddle->SetVisAttributes (G4VisAttributes::GetInvisible());
1099     
1100     ///// FaradayCupBottom /////
1101     
1102     FaradayCupBottom=new G4Tubs ("FaradayCupBottom",
1103                                  InnerRadiusFC,
1104                                  OuterRadiusFC,
1105                                  FaradayCupBottomThickness/2,
1106                                  0*deg,360*deg);
1107     
1108     logicFaradayCupBottom=new G4LogicalVolume(             FaradayCupBottom,
1109                                               FaradayCupBottomMaterial,
1110                                               "logicFaradayCupBottom",
1111                                               0,0,0);
1112     
1113     physicFaradayCupBottom=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(FaradayCupBottomPosX,0,0)),
1114                                              "PhysicFaradayCupBottom",logicFaradayCupBottom,
1115                                              physicVirtualMag,
1116                                              true,0);
1117     logicFaradayCupBottom -> SetVisAttributes(yellow);
1118     
1119     
1120     ///// Virtual Bottom //////
1121     
1122     VirtualBottom=new G4Tubs ("VirtualBottom",
1123                               0,
1124                               OuterRadiusFC,
1125                               VirtualBottomThickness/2,
1126                               0*deg,360*deg);
1127     
1128     logicVirtualBottom=new G4LogicalVolume(                  VirtualBottom,
1129                                            internalChamberMaterial,
1130                                            "logicVirtualBottom",
1131                                            0,0,0);
1132     
1133     physicVirtualBottom=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualBottomPosX,0,0)),
1134                                           "PhysicVirtualBottom",
1135                                           logicVirtualBottom,
1136                                           physicVirtualMag,
1137                                           true,0);
1138     
1139     logicVirtualBottom->SetVisAttributes (G4VisAttributes::GetInvisible());
1140     
1141     ///// Cup /////
1142     
1143     Cup=new G4Tubs ("Cup",
1144                     0,
1145                     OuterRadiusFC,
1146                     CupThickness/2,
1147                     0*deg,360*deg);
1148     
1149     logicCup=new G4LogicalVolume(                           Cup,
1150                                  CupMaterial,
1151                                  "logicCup",
1152                                  0,0,0);
1153     
1154     physicCup=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(CupPosX,0,0)),
1155                                 "PhysicCup", logicCup,
1156                                 
1157                                 physicVirtualMag,
1158                                 true,0);
1159     
1160     logicCup -> SetVisAttributes(darkGreen);
1161     
1162     
1163     ///// Virtual OverBottom /////
1164     
1165     VirtualOverBottom=new G4Tubs ("VirtualOverBottom",
1166                                   0,
1167                                   OuterRadiusFC,
1168                                   VirtualOverBottomThickness/2,
1169                                   0*deg,360*deg);
1170     
1171     logicVirtualOverBottom=new G4LogicalVolume(             VirtualOverBottom,
1172                                                internalChamberMaterial,
1173                                                "logicVirtualOverBottom",
1174                                                0,0,0);
1175     
1176     physicVirtualOverBottom=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualOverBottomPosX,0,0)),
1177                                               "PhysicVirtualOverBottom",logicVirtualOverBottom,
1178                                               
1179                                               physicVirtualMag,
1180                                               true,0);
1181     logicVirtualOverBottom->SetVisAttributes (G4VisAttributes::GetInvisible());
1182     
1183     
1184     ///// Virtual Lateral /////
1185     
1186     
1187     VirtualLateral=new G4Tubs ("VirtualLateral",
1188                                OuterRadiusFC,
1189                                OuterRadiusFC+1*um,// the VirtualLateralThickness is 1*um
1190                                VirtualLateralLength/2,
1191                                0*deg,360*deg);
1192     
1193     logicVirtualLateral=new G4LogicalVolume(                  VirtualLateral,
1194                                             internalChamberMaterial,
1195                                             "logicVirtualLateral",
1196                                             0,0,0);
1197     
1198     physicVirtualLateral=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualLateralPosX,0,0)),
1199                                            "VirtualLateral",logicVirtualLateral,
1200                                            
1201                                            physicVirtualMag,
1202                                            true,0);
1203     
1204     
1205     
1206     logicVirtualLateral->SetVisAttributes (G4VisAttributes::GetInvisible());
1207 }
1208 
1209 /////////////////////////////////////////////////////////////////////////////
1210 void LaserDrivenBeamLine::Quadrupole()
1211 {
1212     // To rotate the quadrupoles putting their axis (along X direction) parallel to the beam axis
1213     G4double phi = 90. *deg;
1214     G4RotationMatrix rm;
1215     rm.rotateY(phi);
1216     
1217     SQuadChamberWall = new G4Box("solidQuadChamberWall",externalChamberXSize/2., externalChamberYSize/2.,externalChamberZSize/2.);
1218     
1219     LQuadChamberWall = new G4LogicalVolume(SQuadChamberWall, externalChamberMaterial,"logicQuadChamberWall");
1220     
1221     PQuadChamberWall = new G4PVPlacement(0, G4ThreeVector(QuadChamberWallPosX, QuadChamberWallPosY, QuadChamberWallPosZ),
1222                                          "physQuadChamberWall", LQuadChamberWall,physicTreatmentRoom, false, 0);
1223     
1224     
1225     SQuadChamber = new G4Box("solidQuadChamber", internalChamberXSize/2., internalChamberYSize/2.,internalChamberZSize/2.);
1226     
1227     LQuadChamber = new G4LogicalVolume(SQuadChamber, internalChamberMaterial,"logicQuadChamber");
1228     
1229     PQuadChamber = new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0),
1230                                      "physQuadChamber", LQuadChamber,PQuadChamberWall, false, 0);
1231     
1232     LQuadChamberWall -> SetVisAttributes(red);
1233     LQuadChamber -> SetVisAttributes(white);
1234     ///////////----------------------------Fourth Quadrupole----------------------------/////////
1235     SFourthTriplet = new G4Tubs("SolidTQuad", InnerRadiusTriplet, ExternalRadiusQuad,((FourthQuadThickness/2.)+1*mm),
1236                                 startAngleQuad, spanningAngleQuad);
1237     
1238     LFourthTriplet = new G4LogicalVolume(SFourthTriplet, internalChamberMaterial,"LogicTQuad", 0, 0, 0);
1239     
1240     PFourthTriplet = new G4PVPlacement(G4Transform3D(rm, G4ThreeVector(FourthQuadXPosition, QuadYPosition, QuadZPosition)),
1241                                        "PhysFourthTQuad", LFourthTriplet, PQuadChamber, false, 0);
1242     
1243     solidFourthQuad = new G4Tubs("SolidQuad", InnerRadiusQuad, ExternalRadiusQuad, FourthQuadThickness/2.,
1244                                  startAngleQuad, spanningAngleQuad);
1245     
1246     logicFourthQuad = new G4LogicalVolume(solidFourthQuad, QuadMaterial, "LogicQuad", 0, 0, 0);
1247     
1248     physicFourthQuad = new G4PVPlacement(0, G4ThreeVector(FourthQXPosition, QYPosition, QZPosition),
1249                                          "PhysFourthQuad",logicFourthQuad, PFourthTriplet, false, 0);
1250     
1251     LFourthTriplet -> SetVisAttributes(yellow);
1252     logicFourthQuad -> SetVisAttributes(green);
1253     ///////////----------------------------Third Quadrupole----------------------------/////////
1254     SThirdTriplet = new G4Tubs("SolidTTQuad", InnerRadiusTriplet, ExternalRadiusQuad, (ThirdQuadThickness/2.)+1*mm,
1255                                startAngleQuad, spanningAngleQuad);
1256     
1257     LThirdTriplet = new G4LogicalVolume(SThirdTriplet, internalChamberMaterial,"LogicTTQuad", 0, 0, 0);
1258     
1259     PThirdTriplet = new G4PVPlacement(G4Transform3D(rm, G4ThreeVector(ThirdQuadXPosition, QuadYPosition, QuadZPosition)),
1260                                       "PhysThirdTQuad",LThirdTriplet,PQuadChamber, false, 0);
1261     
1262     solidThirdQuad = new G4Tubs("SolidTQuad", InnerRadiusQuad, ExternalRadiusQuad, ThirdQuadThickness/2.,
1263                                 startAngleQuad, spanningAngleQuad);
1264     
1265     logicThirdQuad = new G4LogicalVolume(solidThirdQuad, QuadMaterial, "LogicTQuad", 0, 0, 0);
1266     
1267     physicThirdQuad = new G4PVPlacement(0, G4ThreeVector(ThirdQXPosition, QYPosition, QZPosition),
1268                                         "PhysThirdQuad",logicThirdQuad, PThirdTriplet, false, 0);
1269     
1270     LThirdTriplet -> SetVisAttributes(yellow);
1271     logicThirdQuad -> SetVisAttributes(green);
1272     ///////////----------------------------Second Quadrupole----------------------------/////////
1273     SSecondTriplet = new G4Tubs("SolidTSQuad", InnerRadiusTriplet, ExternalRadiusQuad, (SecondQuadThickness/2.)+1*mm,
1274                                 startAngleQuad, spanningAngleQuad);
1275     
1276     LSecondTriplet = new G4LogicalVolume(SSecondTriplet, internalChamberMaterial,"LogicTSQuad", 0, 0, 0);
1277     
1278     PSecondTriplet = new G4PVPlacement(G4Transform3D(rm, G4ThreeVector(SecondQuadXPosition, QuadYPosition, QuadZPosition)),
1279                                        "PhysSecondTQuad", LSecondTriplet, PQuadChamber, false, 0);
1280     
1281     solidSecondQuad = new G4Tubs("SolidSQuad", InnerRadiusQuad, ExternalRadiusQuad, SecondQuadThickness/2.,
1282                                  startAngleQuad, spanningAngleQuad);
1283     
1284     logicSecondQuad = new G4LogicalVolume(solidSecondQuad, QuadMaterial, "LogicSQuad", 0, 0, 0);
1285     
1286     physicSecondQuad = new G4PVPlacement(0, G4ThreeVector(SecondQXPosition, QYPosition, QZPosition),
1287                                          "PhysSecondQuad", logicSecondQuad, PSecondTriplet, false, 0);
1288     
1289     LSecondTriplet -> SetVisAttributes(yellow);
1290     logicSecondQuad -> SetVisAttributes(green);
1291     ///////////----------------------------First Quadrupole----------------------------/////////
1292     SFirstTriplet = new G4Tubs("SolidTQuad", InnerRadiusTriplet, ExternalRadiusQuad, (FirstQuadThickness/2.)+1*mm,
1293                                startAngleQuad, spanningAngleQuad);
1294     
1295     LFirstTriplet = new G4LogicalVolume(SFirstTriplet, internalChamberMaterial,"LogicTQuad", 0, 0, 0);
1296     
1297     PFirstTriplet = new G4PVPlacement(G4Transform3D(rm, G4ThreeVector(FirstQuadXPosition, QuadYPosition, QuadZPosition)),
1298                                       "PhysFirstTQuad", LFirstTriplet, PQuadChamber, false, 0);
1299     
1300     solidFirstQuad = new G4Tubs("SolidQuad", InnerRadiusQuad, ExternalRadiusQuad, FirstQuadThickness/2.,
1301                                 startAngleQuad, spanningAngleQuad);
1302     
1303     logicFirstQuad = new G4LogicalVolume(solidFirstQuad, QuadMaterial, "LogicQuad", 0, 0, 0);
1304     
1305     physicFirstQuad = new G4PVPlacement(0, G4ThreeVector(FirstQXPosition, QYPosition, QZPosition),
1306                                         "PhysFirstQuad",logicFirstQuad, PFirstTriplet, false, 0);
1307     
1308     LFirstTriplet -> SetVisAttributes(yellow);
1309     logicFirstQuad -> SetVisAttributes(green);
1310 }
1311 
1312 /////////////////////////////////////////////////////////////////////////////
1313 void LaserDrivenBeamLine::EnergySelectorChamber()
1314 {
1315     // The whole energyselector is mounted inside a
1316     // a vacuum chamber  (called 'ExternalChamber')
1317     // inside which a vacuum box is inserted.
1318     
1319     solidExternalChamber = new G4Box("ExternalChamber",
1320                                      externalChamberXSize/2.0,
1321                                      externalChamberYSize/2.0,
1322                                      externalChamberZSize/2.0);
1323     
1324     logicExternalChamber = new G4LogicalVolume(solidExternalChamber,
1325                                                externalChamberMaterial,
1326                                                "ExternalChamber");
1327     
1328     physicExternalChamber = new G4PVPlacement(0,
1329                                               G4ThreeVector(externalChamberXPosition,
1330                                                             externalChamberYPosition,
1331                                                             externalChamberZPosition),
1332                                               "ExternalChamber",
1333                                               logicExternalChamber,
1334                                               physicTreatmentRoom,
1335                                               false,
1336                                               0);
1337     
1338     // Visualisation of the External part
1339     logicExternalChamber -> SetVisAttributes(red);
1340     
1341     // This is a vacuum box inside the steel box
1342     solidInternalChamber = new G4Box("SInternalChamber",
1343                                      internalChamberXSize/2.0,
1344                                      internalChamberYSize/2.0,
1345                                      internalChamberZSize/2.0);
1346     
1347     logicInternalChamber = new G4LogicalVolume(solidInternalChamber,
1348                                                internalChamberMaterial,
1349                                                "LInternalChamber");
1350     
1351     physicInternalChamber = new G4PVPlacement(0,
1352                                               G4ThreeVector(0,0,0),
1353                                               "InternalChamber",
1354                                               logicInternalChamber,
1355                                               physicExternalChamber,
1356                                               false,
1357                                               0);
1358     logicInternalChamber -> SetVisAttributes(white);
1359 }
1360 
1361 //////////////////////////////////////////////////// Entrance pipe ///////////////////////
1362 void LaserDrivenBeamLine::EntrancePipe()
1363 {
1364     // To rotate the EntrancePipe putting its axis (along X direction) parallel to the beam axis
1365     G4double phi = 90. *deg;
1366     G4RotationMatrix rm;
1367     rm.rotateY(phi);
1368     
1369     solidEntrancePipe = new G4Tubs("EntrancePipe",
1370                                    InnerRadiusEntrancePipe,
1371                                    ExternalRadiusEntrancePipe,
1372                                    EntrancePipeheight/2.,
1373                                    startAngleEntrancePipe,
1374                                    spanningAngleEntrancePipe);
1375     
1376     logicEntrancePipe = new G4LogicalVolume(solidEntrancePipe,
1377                                             PipeMaterial,
1378                                             "EntrancePipe",
1379                                             0,
1380                                             0,
1381                                             0);
1382     
1383     physicEntrancePipe = new G4PVPlacement(G4Transform3D(rm,
1384                                                          G4ThreeVector(EntrancePipeXPosition,
1385                                                                        EntrancePipeYPosition,
1386                                                                        EntrancePipeZPosition)),
1387                                            "EntrancePipe",
1388                                            logicEntrancePipe,
1389                                            physicTreatmentRoom,
1390                                            false,
1391                                            0);
1392     
1393     logicEntrancePipe -> SetVisAttributes(red);
1394     
1395 }
1396 
1397 //////////////////////////////////////////////////// Entrance hole ///////////////////////
1398 void LaserDrivenBeamLine::Entrancehole()
1399 {
1400     // To rotate the ExitPipe putting its axis (along X direction) parallel to the beam axis
1401     G4double phi = 90. *deg;
1402     G4RotationMatrix rm;
1403     rm.rotateY(phi);
1404     
1405     solidEntrancehole = new G4Tubs("Entrancehole",
1406                                    InnerRadiusEntrancehole,
1407                                    ExternalRadiusEntrancehole,
1408                                    EntranceholeThickness/2.,
1409                                    startAngleEntrancehole,
1410                                    spanningAngleEntrancehole);
1411     
1412     logicEntrancehole = new G4LogicalVolume(solidEntrancehole,
1413                                             internalChamberMaterial,
1414                                             "Entrancehole",
1415                                             0,
1416                                             0,
1417                                             0);
1418     //the hole in the energy selector chamber
1419     physicEntranceholeESSChamber = new G4PVPlacement(G4Transform3D(rm,
1420                                                                    G4ThreeVector(EntranceholeXPosition,
1421                                                                                  EntranceholeYPosition,
1422                                                                                  EntranceholeZPosition)),
1423                                                      "Entrancehole",
1424                                                      logicEntrancehole,
1425                                                      physicExternalChamber,
1426                                                      false,
1427                                                      0);
1428     //the hole in the quadrupoles chamber
1429     physicEntrancehole = new G4PVPlacement(G4Transform3D(rm,
1430                                                          G4ThreeVector(EntranceholeQuadXPosition,
1431                                                                        EntranceholeYPosition,
1432                                                                        EntranceholeZPosition)),
1433                                            "EntranceholeQuad",
1434                                            logicEntrancehole,
1435                                            PQuadChamberWall,
1436                                            false,
1437                                            0);
1438     
1439     logicEntrancehole -> SetVisAttributes(skyBlue);
1440     
1441     
1442 }
1443 /////////////////////////////////////////////////////////////////////////////
1444 void LaserDrivenBeamLine::Collimator()
1445 {
1446     // To rotate the collimator putting its axis (along X direction) parallel to the beam axis
1447     G4double phi = 90. *deg;
1448     G4RotationMatrix rm;
1449     rm.rotateY(phi);
1450     //8x82x210 mm are the collimator default dimensions
1451     solidCollimator = new G4Box("collimator",
1452                                 thicknessCollimator/2.0,
1453                                 collimatorBoxYSize/2.0,
1454                                 collimatorBoxZSize/2.0);
1455     
1456     logicCollimator = new G4LogicalVolume(solidCollimator,
1457                                           collimatorMaterial,
1458                                           "collimator");
1459     
1460     physicCollimator = new G4PVPlacement(0,
1461                                          G4ThreeVector(collimatorBox_XPosition,
1462                                                        collimatorBox_YPosition,
1463                                                        collimatorBox_ZPosition),
1464                                          "collimator",
1465                                          logicCollimator,
1466                                          physicInternalChamber,
1467                                          false,
1468                                          0);
1469     
1470     logicCollimator -> SetVisAttributes(darkOrange3);
1471     
1472     solidCollimatorHole = new G4Tubs("CollimatorHole",
1473                                      innerRadiusCollimator,
1474                                      outerRadiusCollimator,
1475                                      thicknessCollimator/2.,
1476                                      startAngleCollimator,
1477                                      spanningAngleCollimator);
1478     
1479     logicCollimatorHole = new G4LogicalVolume(solidCollimatorHole,
1480                                               collimatorHoleMaterial,
1481                                               "CollimatorHole",
1482                                               0,
1483                                               0,
1484                                               0);
1485     
1486     physicCollimatorHole = new G4PVPlacement(G4Transform3D(rm,
1487                                                            G4ThreeVector(collimatorXPosition,
1488                                                                          collimatorYPosition,
1489                                                                          collimatorZPosition)),
1490                                              "CollimatorHole",
1491                                              logicCollimatorHole,
1492                                              physicCollimator,
1493                                              false,
1494                                              0);
1495     
1496     logicCollimatorHole -> SetVisAttributes(skyBlue);
1497 }
1498 
1499 /////////////////////////////////////////////////////////////////////////////
1500 // Magnet number 1
1501 void LaserDrivenBeamLine::Magnet_1()
1502 {  // The positions of the external and internal partes are given as respect the external chamber.
1503     solidExternalMagnet_1 = new G4Box("SolidExternalMagnet_1",
1504                                       externalMagnet_1XSize/2.0,
1505                                       externalMagnet_1YSize/2.0,
1506                                       externalMagnet_1ZSize/2.0);
1507     
1508     logicExternalMagnet_1 = new G4LogicalVolume(solidExternalMagnet_1,
1509                                                 externalMagnet_1Material,
1510                                                 "LogicExternalMagnet_1");
1511     
1512     physicExternalMagnet_1 = new G4PVPlacement(0,
1513                                                G4ThreeVector(externalMagnet_1XPosition,
1514                                                              externalMagnet_2YPosition,
1515                                                              externalMagnet_2ZPosition),
1516                                                "PhysicExternalMagnet_1",
1517                                                logicExternalMagnet_1,
1518                                                physicInternalChamber,
1519                                                false,
1520                                                0);
1521     physicExternalMagnet_1Down = new G4PVPlacement(0,
1522                                                    G4ThreeVector(externalMagnet_1XPosition,
1523                                                                  -externalMagnet_2YPosition,
1524                                                                  externalMagnet_2ZPosition),
1525                                                    "PhysicExternalMagnet_1Down",
1526                                                    logicExternalMagnet_1,
1527                                                    physicInternalChamber,
1528                                                    false,
1529                                                    0);
1530     
1531     
1532     logicExternalMagnet_1 -> SetVisAttributes(gray);
1533     
1534     // The right and left part of the magnet
1535     solidMagnet_1 = new G4Box("SolidMagnet_1",
1536                               Magnet_1XSize/2.0,
1537                               Magnet_1YSize/2.0,
1538                               Magnet_1ZSize/2.0);
1539     
1540     logicMagnet_1 = new G4LogicalVolume(solidMagnet_1,
1541                                         externalMagnet_1Material,
1542                                         "LogicMagnet_1");
1543     
1544     physicMagnet_1Right = new G4PVPlacement(0,
1545                                             G4ThreeVector(Magnet_1XPosition,Magnet_1YPosition,
1546                                                           Magnet_1ZPosition),
1547                                             "PhysicMagnet_1Right",
1548                                             logicMagnet_1,
1549                                             physicInternalChamber,
1550                                             false,
1551                                             0);
1552     physicMagnet_1Left = new G4PVPlacement(0,
1553                                            G4ThreeVector(Magnet_1XPosition,Magnet_1YPosition,
1554                                                          -Magnet_1ZPosition),
1555                                            "PhysicMagnet_1Left",
1556                                            logicMagnet_1,
1557                                            physicInternalChamber,
1558                                            false,
1559                                            0);
1560     
1561     logicMagnet_1 -> SetVisAttributes(gray);
1562 }
1563 
1564 /////////////////////////////////////////////////////////////////////////////
1565 // Magnet number 2
1566 void LaserDrivenBeamLine::Magnet_2()
1567 { // The position of the external part are given as respect the external chamber.
1568     
1569     solidExternalMagnet_2 = new G4Box("SolidExternalMagnet_2",
1570                                       externalMagnet_2XSize/2.0,
1571                                       externalMagnet_2YSize/2.0,
1572                                       externalMagnet_2ZSize/2.0);
1573     
1574     logicExternalMagnet_2 = new G4LogicalVolume(solidExternalMagnet_2,
1575                                                 externalMagnet_2Material,
1576                                                 "LogicExternalMagnet_2");
1577     
1578     physicExternalMagnet_2 = new G4PVPlacement(0,
1579                                                G4ThreeVector(externalMagnet_2XPosition,
1580                                                              externalMagnet_2YPosition,
1581                                                              (externalMagnet_2ZPosition+32*mm)),
1582                                                "PhysicExternalMagnet_2",
1583                                                logicExternalMagnet_2,
1584                                                physicInternalChamber,
1585                                                false,
1586                                                0);
1587     
1588     physicExternalMagnet_2Down = new G4PVPlacement(0,
1589                                                    G4ThreeVector(externalMagnet_2XPosition,
1590                                                                  -externalMagnet_2YPosition,
1591                                                                  (externalMagnet_2ZPosition+32*mm)),
1592                                                    "PhysicExternalMagnet_2Down",
1593                                                    logicExternalMagnet_2,
1594                                                    physicInternalChamber,
1595                                                    false,
1596                                                    0);
1597     
1598     
1599     logicExternalMagnet_2 -> SetVisAttributes(gray);
1600     
1601     // The right and left part of the magnet
1602     solidMagnet_2 = new G4Box("SolidMagnet_2",
1603                               Magnet_2XSize/2.0,
1604                               Magnet_2YSize/2.0,
1605                               Magnet_2ZSize/2.0);
1606     
1607     logicMagnet_2 = new G4LogicalVolume(solidMagnet_2,
1608                                         externalMagnet_2Material,
1609                                         "LogicMagnet_2");
1610     
1611     physicMagnet_2Right = new G4PVPlacement(0,
1612                                             G4ThreeVector(Magnet_2XPosition,Magnet_2YPosition,
1613                                                           (Magnet_2ZPosition)+32*mm),
1614                                             "PhysicMagnet_2Right",
1615                                             logicMagnet_2,
1616                                             physicInternalChamber,
1617                                             false,
1618                                             0);
1619     physicMagnet_2Left = new G4PVPlacement(0,
1620                                            G4ThreeVector(Magnet_2XPosition,Magnet_2YPosition,
1621                                                          (-(Magnet_2ZPosition)+32*mm)),
1622                                            "PhysicMagnet_2Left",
1623                                            logicMagnet_2,
1624                                            physicInternalChamber,
1625                                            false,
1626                                            0);
1627     logicMagnet_2 -> SetVisAttributes(gray);
1628 }
1629 
1630 /////////////////////////////////////////////////////////////////////////////
1631 // Magnet number 3
1632 void LaserDrivenBeamLine::Magnet_3()
1633 { // The position of the external part are given as respect the external chamber.
1634     
1635     solidExternalMagnet_3 = new G4Box("SolidExternalMagnet_3",
1636                                       externalMagnet_3XSize/2.0,
1637                                       externalMagnet_3YSize/2.0,
1638                                       externalMagnet_3ZSize/2.0);
1639     
1640     logicExternalMagnet_3 = new G4LogicalVolume(solidExternalMagnet_3,
1641                                                 externalMagnet_3Material,
1642                                                 "LogicExternalMagnet_3");
1643     
1644     physicExternalMagnet_3 = new G4PVPlacement(0,
1645                                                G4ThreeVector((externalMagnet_3XPosition),
1646                                                              externalMagnet_3YPosition,
1647                                                              (externalMagnet_3ZPosition+32*mm)),
1648                                                "PhysicExternalMagnet_3",
1649                                                logicExternalMagnet_3,
1650                                                physicInternalChamber,
1651                                                false,
1652                                                0);
1653     
1654     physicExternalMagnet_3Down = new G4PVPlacement(0,
1655                                                    G4ThreeVector((externalMagnet_3XPosition),
1656                                                                  -externalMagnet_3YPosition,
1657                                                                  (externalMagnet_3ZPosition+32*mm)),
1658                                                    "PhysicExternalMagnet_3Down",
1659                                                    logicExternalMagnet_3,
1660                                                    physicInternalChamber,
1661                                                    false,
1662                                                    0);
1663     
1664     logicExternalMagnet_3 -> SetVisAttributes(gray);
1665     
1666     // The right and left part of the magnet
1667     solidMagnet_3 = new G4Box("SolidMagnet_3",
1668                               Magnet_3XSize/2.0,
1669                               Magnet_3YSize/2.0,
1670                               Magnet_3ZSize/2.0);
1671     
1672     logicMagnet_3 = new G4LogicalVolume(solidMagnet_3,
1673                                         externalMagnet_3Material,
1674                                         "LogicMagnet_3");
1675     
1676     physicMagnet_3Right = new G4PVPlacement(0,
1677                                             G4ThreeVector(Magnet_3XPosition,Magnet_3YPosition,
1678                                                           (Magnet_3ZPosition+32*mm)),
1679                                             "PhysicMagnet_3Right",
1680                                             logicMagnet_3,
1681                                             physicInternalChamber,
1682                                             false,
1683                                             0);
1684     physicMagnet_3Left = new G4PVPlacement(0,
1685                                            G4ThreeVector(Magnet_3XPosition,Magnet_3YPosition,
1686                                                          (-(Magnet_3ZPosition)+32*mm)),
1687                                            "PhysicMagnet_3Left",
1688                                            logicMagnet_3,
1689                                            physicInternalChamber,
1690                                            false,
1691                                            0);
1692     logicMagnet_3 -> SetVisAttributes(gray);
1693     
1694 }
1695 
1696 /////////////////////////////////////////////////////////////////////////////
1697 // Magnet number 4
1698 void LaserDrivenBeamLine::Magnet_4()
1699 { // The position of the external part are given as respect the external chamber.
1700     
1701     solidExternalMagnet_4 = new G4Box("SolidExternalMagnet_4",
1702                                       externalMagnet_4XSize/2.0,
1703                                       externalMagnet_4YSize/2.0,
1704                                       externalMagnet_4ZSize/2.0);
1705     
1706     logicExternalMagnet_4 = new G4LogicalVolume(solidExternalMagnet_4,
1707                                                 externalMagnet_4Material,
1708                                                 "LogicExternalMagnet_4");
1709     
1710     physicExternalMagnet_4 = new G4PVPlacement(0,
1711                                                G4ThreeVector(externalMagnet_4XPosition,
1712                                                              externalMagnet_4YPosition,
1713                                                              externalMagnet_4ZPosition),
1714                                                "PhysicExternalMagnet_4",
1715                                                logicExternalMagnet_4,
1716                                                physicInternalChamber,
1717                                                false,
1718                                                0);
1719     
1720     physicExternalMagnet_4Down = new G4PVPlacement(0,
1721                                                    G4ThreeVector(externalMagnet_4XPosition,
1722                                                                  -externalMagnet_4YPosition,
1723                                                                  externalMagnet_4ZPosition),
1724                                                    "PhysicExternalMagnet_4Down",
1725                                                    logicExternalMagnet_4,
1726                                                    physicInternalChamber,
1727                                                    false,
1728                                                    0);
1729     
1730     logicExternalMagnet_4 -> SetVisAttributes(gray);
1731     
1732     // The right and left part of the magnet
1733     solidMagnet_4 = new G4Box("SolidMagnet_4",
1734                               Magnet_4XSize/2.0,
1735                               Magnet_4YSize/2.0,
1736                               Magnet_4ZSize/2.0);
1737     
1738     logicMagnet_4 = new G4LogicalVolume(solidMagnet_4,
1739                                         externalMagnet_4Material,
1740                                         "LogicMagnet_4");
1741     
1742     physicMagnet_4Right = new G4PVPlacement(0,
1743                                             G4ThreeVector(Magnet_4XPosition,Magnet_4YPosition,
1744                                                           Magnet_4ZPosition),
1745                                             "PhysicMagnet_4Right",
1746                                             logicMagnet_4,
1747                                             physicInternalChamber,
1748                                             false,
1749                                             0);
1750     physicMagnet_4Left = new G4PVPlacement(0,
1751                                            G4ThreeVector(Magnet_4XPosition,Magnet_4YPosition,
1752                                                          -Magnet_4ZPosition),
1753                                            "PhysicMagnet_4Left",
1754                                            logicMagnet_4,
1755                                            physicInternalChamber,
1756                                            false,
1757                                            0);
1758     logicMagnet_4 -> SetVisAttributes(gray);
1759 }
1760 
1761 /////////////////////////////////////////////////////////////////////////////
1762 // Slit
1763 void LaserDrivenBeamLine::Slit()
1764 {
1765     solidExternalSlit = new G4Box("ExternalSlit",
1766                                   externalSlitXSize/2.0,
1767                                   externalSlitYSize/2.0,
1768                                   externalSlitZSize/2.0);
1769     
1770     logicExternalSlit = new G4LogicalVolume(solidExternalSlit,
1771                                             externalSlitMaterial,
1772                                             "ExternalSlit");
1773     
1774     physicExternalSlit = new G4PVPlacement(0,
1775                                            G4ThreeVector(externalSlitXPosition,
1776                                                          externalSlitYPosition,
1777                                                          externalSlitZPosition),
1778                                            "ExternalSlit",
1779                                            logicExternalSlit,
1780                                            physicInternalChamber,
1781                                            false,
1782                                            0);
1783     
1784     logicExternalSlit -> SetVisAttributes(green);
1785     // The hole
1786     solidInternalSlit = new G4Box("InternalSlit",
1787                                   internalSlitXSize/2.0,
1788                                   internalSlitYSize/2.0,
1789                                   internalSlitZSize/2.0);
1790     
1791     logicInternalSlit = new G4LogicalVolume(solidInternalSlit,
1792                                             internalSlitMaterial,
1793                                             "InternalSlit");
1794     
1795     physicInternalSlit = new G4PVPlacement(0,
1796                                            G4ThreeVector(internalSlitXPosition,
1797                                                          internalSlitYPosition,
1798                                                          internalSlitZPosition),
1799                                            "InternalSlit",
1800                                            logicInternalSlit,
1801                                            physicExternalSlit,
1802                                            false,
1803                                            0);
1804     
1805     logicInternalSlit -> SetVisAttributes(skyBlue);
1806     
1807 }
1808 ////////////////////////////////////// Final collimator ////////////////////////////////////////////
1809 void LaserDrivenBeamLine::FinalCollimator()
1810 {
1811     // To rotate the collimator putting its axis (along X direction) parallel to the beam axis
1812     G4double phi = 90. *deg;
1813     G4RotationMatrix rm;
1814     rm.rotateY(phi);
1815     
1816     solidFinalCollimator = new G4Box("collimatorFinal",
1817                                      collimatorFinalBoxXSize/2.0,
1818                                      collimatorFinalBoxYSize/2.0,
1819                                      collimatorFinalBoxZSize/2.0);
1820     
1821     logicFinalCollimator = new G4LogicalVolume(solidFinalCollimator,
1822                                                FinalcollimatorMaterial,
1823                                                "collimatorFinal");
1824     
1825     physicFinalCollimator = new G4PVPlacement(0,
1826                                               G4ThreeVector(collimatorFinalBox_XPosition,
1827                                                             collimatorFinalBox_YPosition,
1828                                                             collimatorFinalBox_ZPosition),
1829                                               "collimatorFinal",
1830                                               logicFinalCollimator,
1831                                               physicInternalChamber,
1832                                               false,
1833                                               0);
1834     logicFinalCollimator -> SetVisAttributes(darkOrange3);
1835     
1836     solidFinalCollimatorHole= new G4Tubs("FinalCollimatorHole",
1837                                          innerRadiusFinalCollimator,
1838                                          outerRadiusFinalCollimator,
1839                                          FinalCollimatorThickness/2.,
1840                                          startAngleFinalCollimator,
1841                                          spanningAngleFinalCollimator);
1842     
1843     logicFinalCollimatorHole = new G4LogicalVolume(solidFinalCollimatorHole,
1844                                                    FinalcollimatorHoleMaterial,
1845                                                    "FinalCollimatorHole",
1846                                                    0,
1847                                                    0,
1848                                                    0);
1849     
1850     physicFinalCollimatorHole = new G4PVPlacement(G4Transform3D(rm,
1851                                                                 G4ThreeVector(FinalcollimatorXPosition,
1852                                                                               FinalcollimatorYPosition,
1853                                                                               FinalcollimatorZPosition)),
1854                                                   "FinalCollimatorHole",
1855                                                   logicFinalCollimatorHole,
1856                                                   physicFinalCollimator,
1857                                                   false,
1858                                                   0);
1859     logicFinalCollimatorHole -> SetVisAttributes(skyBlue);
1860 }
1861 //////////////////////////// Exit Window ////////////////////////////////////////////
1862 void LaserDrivenBeamLine::ExitWindow()
1863 {
1864     // To rotate the ExitWindow putting its axis (along X direction) parallel to the beam axis
1865     G4double phi = 90. *deg;
1866     G4RotationMatrix rm;
1867     rm.rotateY(phi);
1868     
1869     solidExitWindow = new G4Tubs("ExitWindow",
1870                                  InnerRadiusExitWindow,
1871                                  ExternalRadiusExitWindow,
1872                                  ExitWindowThickness/2.,
1873                                  startAngleExitWindow,
1874                                  spanningAngleExitWindow);
1875     
1876     logicExitWindow = new G4LogicalVolume(solidExitWindow,
1877                                           WindowMaterial,
1878                                           "ExitWindow",
1879                                           0,
1880                                           0,
1881                                           0);
1882     
1883     physicExitWindow = new G4PVPlacement(G4Transform3D(rm,
1884                                                        G4ThreeVector(ExitWindowXPosition,
1885                                                                      ExitWindowYPosition,
1886                                                                      ExitWindowZPosition)),
1887                                          "ExitWindow",
1888                                          logicExitWindow,
1889                                          physicTreatmentRoom,
1890                                          false,
1891                                          0);
1892     
1893     logicExitWindow -> SetVisAttributes(skyBlue);
1894     
1895 }
1896 
1897 //////////////////////////////////////////////////// Exit pipe ///////////////////////
1898 void LaserDrivenBeamLine::ExitPipe()
1899 {
1900     // To rotate the ExitPipe putting its axis (along X direction) parallel to the beam axis
1901     G4double phi = 90. *deg;
1902     G4RotationMatrix rm;
1903     rm.rotateY(phi);
1904     
1905     solidExitPipe = new G4Tubs("ExitPipe",
1906                                InnerRadiusExitPipe,
1907                                ExternalRadiusExitPipe,
1908                                ExitPipeheight/2.,
1909                                startAngleExitPipe,
1910                                spanningAngleExitPipe);
1911     
1912     logicExitPipe = new G4LogicalVolume(solidExitPipe,
1913                                         PipeMaterial,
1914                                         "ExitPipe",
1915                                         0,
1916                                         0,
1917                                         0);
1918     
1919     physicExitPipe = new G4PVPlacement(G4Transform3D(rm,
1920                                                      G4ThreeVector(ExitPipeXPosition,
1921                                                                    ExitPipeYPosition,
1922                                                                    ExitPipeZPosition)),
1923                                        "ExitPipe",
1924                                        logicExitPipe,
1925                                        physicTreatmentRoom,
1926                                        false,
1927                                        0);
1928     
1929     logicExitPipe -> SetVisAttributes(red);
1930     
1931 }
1932 
1933 ///////////////////////////////////// Exit hole ///////////////////////
1934 void LaserDrivenBeamLine::Exithole()
1935 {
1936     // To rotate the ExitPipe putting its axis (along X direction) parallel to the beam axis
1937     G4double phi = 90. *deg;
1938     G4RotationMatrix rm;
1939     rm.rotateY(phi);
1940     
1941     solidExithole = new G4Tubs("Exithole",
1942                                InnerRadiusExithole,
1943                                ExternalRadiusExithole,
1944                                ExitholeThickness/2.,
1945                                startAngleExithole,
1946                                spanningAngleExithole);
1947     
1948     logicExithole = new G4LogicalVolume(solidExithole,
1949                                         internalChamberMaterial,
1950                                         "Exithole",
1951                                         0,
1952                                         0,
1953                                         0);
1954     
1955     physicExithole = new G4PVPlacement(G4Transform3D(rm,
1956                                                      G4ThreeVector(ExitholeXPosition,
1957                                                                    ExitholeYPosition,
1958                                                                    ExitholeZPosition)),
1959                                        "Exithole",
1960                                        logicExithole,
1961                                        physicExternalChamber,
1962                                        false,
1963                                        0);
1964     
1965     logicExithole -> SetVisAttributes(skyBlue);
1966     
1967 }
1968 /////////////////////////// MESSENGER ///////////////////////////////////////
1969 /////////////////////////////////////////////////////////////////////////////
1970 // Disable via external macro command the Energy Selector System
1971 void LaserDrivenBeamLine::RemoveESS()
1972 {
1973     if(physicMagnet_1Left) {delete physicMagnet_1Left; delete physicMagnet_1Right; delete logicMagnet_1; delete solidMagnet_1;}
1974     if(physicExternalMagnet_1Down){delete physicExternalMagnet_1Down; delete physicExternalMagnet_1; delete logicExternalMagnet_1; delete solidExternalMagnet_1;}
1975     if(physicMagnet_2Left){delete physicMagnet_2Left; delete physicMagnet_2Right; delete logicMagnet_2; delete solidMagnet_2;}
1976     if(physicExternalMagnet_2Down){ delete physicExternalMagnet_2Down; delete physicExternalMagnet_2; delete logicExternalMagnet_2; delete solidExternalMagnet_2; }
1977     if(physicMagnet_3Left){delete physicMagnet_3Left; delete physicMagnet_3Right; delete logicMagnet_3; delete solidMagnet_3; }
1978     if(physicExternalMagnet_3Down){delete physicExternalMagnet_3Down; delete physicExternalMagnet_3; delete logicExternalMagnet_3; delete solidExternalMagnet_3; }
1979     if(physicMagnet_4Left) {delete physicMagnet_4Left; delete physicMagnet_4Right; delete logicMagnet_4; delete solidMagnet_4; }
1980     if(physicExternalMagnet_4Down){delete physicExternalMagnet_4Down; delete physicExternalMagnet_4; delete logicExternalMagnet_4; delete solidExternalMagnet_4; }
1981     if(physicCollimatorHole){delete physicCollimatorHole; delete logicCollimatorHole; delete solidCollimatorHole; }
1982     if(physicCollimator) {delete physicCollimator; delete logicCollimator; delete solidCollimator; }
1983     if(physicFinalCollimatorHole) {delete physicFinalCollimatorHole; delete logicFinalCollimatorHole; delete solidFinalCollimatorHole; }
1984     if(physicFinalCollimator){delete physicFinalCollimator; delete logicFinalCollimator; delete solidFinalCollimator; }
1985     if(physicInternalSlit){ delete physicInternalSlit; delete logicInternalSlit; delete solidInternalSlit; }
1986     if(physicExternalSlit){delete physicExternalSlit; delete logicExternalSlit; delete solidExternalSlit; }
1987     if(physicExithole){delete physicExithole; delete logicExithole; delete solidExithole;}
1988     if(physicExitWindow){delete physicExitWindow; delete logicExitWindow; delete solidExitWindow;}
1989     if(physicExitPipe){delete physicExitPipe; delete logicExitPipe; delete solidExitPipe;}
1990     if(physicEntranceholeESSChamber){delete physicEntranceholeESSChamber;}
1991     if(physicInternalChamber){delete physicInternalChamber; delete logicInternalChamber; delete solidInternalChamber;}
1992     if(physicExternalChamber) {delete physicExternalChamber; delete logicExternalChamber; delete solidExternalChamber;}
1993     if(pFieldMgr) {delete pFieldMgr;}
1994     
1995     
1996     
1997     G4cout << "****************************************************" << G4endl;
1998     G4cout << "************ The ESS has been disabled *************"  << G4endl;
1999     G4cout << "****************************************************" << G4endl;
2000     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2001 
2002     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2003 
2004 }
2005 // Change via external macro command the diameter of the first collimator
2006 void LaserDrivenBeamLine::SetFirstCollimatorRadius(G4double valueR)
2007 {
2008     G4double radius = valueR;
2009     solidCollimatorHole -> SetOuterRadius(radius);
2010     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2011 
2012     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2013 
2014     G4cout << "The first collimator aperture has been modified to "<< valueR/mm <<"mm in diameter" << G4endl;
2015 }
2016 /////////////////////////////////////////////////////////////////////////////
2017 // Change via external macro command the thickness of the first collimator
2018 void LaserDrivenBeamLine::SetFirstCollimatorThickness(G4double valueC)
2019 {
2020     G4double thickness = valueC/2;
2021     solidCollimator -> SetXHalfLength(thickness);
2022     solidCollimatorHole -> SetZHalfLength(thickness);
2023     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2024 
2025     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2026 
2027     G4cout << "The first collimator thickness has been modified to "<< valueC/mm <<" mm in thickness" << G4endl;
2028 }
2029 
2030 // Change via external macro command the Z position of the first collimator hole
2031 void LaserDrivenBeamLine::SetFirstCollimatorPositionZ(G4double valueQ)
2032 {
2033     physicCollimatorHole -> SetTranslation(G4ThreeVector(0., 0., valueQ));
2034     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2035 
2036     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2037 
2038     G4cout << "The first collimator has been translated to "<< valueQ/mm <<"mm (along the z axis)" << G4endl;
2039 }
2040 
2041 // Change via external macro command the diameter of the second collimator
2042 void LaserDrivenBeamLine::SetSecondCollimatorRadius(G4double value)
2043 {
2044     G4double radius = value;
2045     solidFinalCollimatorHole -> SetOuterRadius(radius);
2046     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2047 
2048     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2049 
2050     G4cout << "The second collimator aperture has been modified to "<< value/mm <<"mm in diameter" << G4endl;
2051 }
2052 
2053 /////////////////////////////////////////////////////////////////////////////
2054 // Change via external macro command the thickness of the second collimator
2055 void LaserDrivenBeamLine::SetSecondCollimatorThickness(G4double value)
2056 {
2057     G4double thickness = value/2;
2058     solidFinalCollimator -> SetXHalfLength(thickness);
2059     solidFinalCollimatorHole -> SetZHalfLength(thickness);
2060     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2061 
2062     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2063 
2064     G4cout << "The second collimator thickness has been modified to "<< value/mm <<" mm in thickness" << G4endl;
2065 }
2066 
2067 // Change via external macro command the Z position of the second collimator hole
2068 void LaserDrivenBeamLine::SetSecondCollimatorPositionZ(G4double value)
2069 {
2070     physicFinalCollimatorHole -> SetTranslation(G4ThreeVector(0., 0., value));
2071     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2072 
2073     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2074 
2075     G4cout << "The second collimator has been translated to "<< value/mm <<"mm (along the z axis)" << G4endl;
2076 }
2077 // THE SLIT MESSENGERS
2078 /////////////////////////////////////////////////////////////////////////////
2079 // Change the thickness of the Slit
2080 void LaserDrivenBeamLine::SetThicknessSlit(G4double value)
2081 {
2082     if (value >(10.0*mm)) {
2083         G4cout <<"***************************************"<< G4endl;
2084         G4cout <<"******This is a warning messenger******"<< G4endl;
2085         G4cout <<"***************************************"<< G4endl;
2086         G4cout <<"The maximum value of the thickness of the slit is 10 mm, your value is >10 mm." << G4endl;
2087         G4cout <<"The default thickness value is used, it is: " << ((solidExternalSlit -> GetXHalfLength())*2.)/mm
2088         << G4endl;
2089         G4cout <<"***************************************"<< G4endl;
2090         
2091     }
2092     else  {
2093         G4double dimension = value/2;
2094         solidExternalSlit -> SetXHalfLength(dimension);
2095         solidInternalSlit -> SetXHalfLength(dimension);
2096         G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2097 
2098         G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2099 
2100         G4cout <<"The thickness of the slit is:" << ((solidExternalSlit -> GetXHalfLength())*2.)/mm
2101         << G4endl;
2102     }
2103 }
2104 /////////////////////////////////////////////////////////////////////////////
2105 // Change the hole size (in Y direction) of the Slit
2106 void LaserDrivenBeamLine::SetSlitHoleDimensionY(G4double value)
2107 {
2108     G4double hole = value/2;
2109     solidInternalSlit -> SetYHalfLength(hole);
2110     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2111 
2112     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2113 
2114     G4cout << "The hole of the Slit has been changed in the Y direction to "<< value/mm <<" mm" <<G4endl;
2115 }
2116 
2117 /////////////////////////////////////////////////////////////////////////////
2118 // Change the hole size (in Z direction) of the Slit
2119 void LaserDrivenBeamLine::SetSlitHoleDimensionZ(G4double value)
2120 {
2121     G4double hole = value/2;
2122     solidInternalSlit -> SetZHalfLength(hole);
2123     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2124 
2125     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2126 
2127     G4cout << "The hole of the Slit has been changed in the Z direction to "<< value/mm <<" mm" <<G4endl;
2128 }
2129 /////////////////////////////////////////////////////////////////////////////
2130 // Change the Z position of the hole of the Slit
2131 void LaserDrivenBeamLine::SetSlitHolePositionZ(G4double value)
2132 {
2133     physicInternalSlit -> SetTranslation(G4ThreeVector(0., 0., value));
2134     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2135 
2136     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2137 
2138     G4cout << "The hole of the slit has been translated to "<< value/mm <<" mm (along the Z axis)" <<G4endl;
2139 }
2140 
2141 // QUADRUPOLES
2142 
2143 // Disable via external macro command all quadrupoles
2144 void LaserDrivenBeamLine::RemoveQuads()
2145 {
2146     if(physicFirstQuad)
2147     {delete solidFirstQuad; delete logicFirstQuad; delete physicFirstQuad;delete SFirstTriplet; delete LFirstTriplet; delete PFirstTriplet;}
2148     if(physicSecondQuad)
2149     {delete solidSecondQuad; delete logicSecondQuad; delete physicSecondQuad;delete SSecondTriplet; delete LSecondTriplet;  delete PSecondTriplet;}
2150     if(physicThirdQuad)
2151     {delete solidThirdQuad; delete logicThirdQuad; delete physicThirdQuad;delete SThirdTriplet; delete LThirdTriplet;   delete PThirdTriplet;}
2152     if(physicFourthQuad)
2153     {delete solidFourthQuad; delete logicFourthQuad; delete physicFourthQuad;delete SFourthTriplet; delete LFourthTriplet;  delete PFourthTriplet;}
2154     if(pFieldMgrQuadFourth) {delete pFieldMgrQuadFourth;}
2155     if(pFieldMgrQuadThird) {delete pFieldMgrQuadThird;}
2156     if(pFieldMgrQuadSecond) {delete pFieldMgrQuadSecond;}
2157     if(pFieldMgrQuadFirst) {delete pFieldMgrQuadFirst;}
2158     
2159     
2160     G4cout << "******************************************************************" << G4endl;
2161     G4cout << "************ The Quadrupoles system has been disabled *************"  << G4endl;
2162     G4cout << "******************************************************************" << G4endl;
2163     G4RunManager::GetRunManager() -> GeometryHasBeenModified();
2164 
2165     G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2166 
2167 }
2168 
2169