ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LaserDrivenBeamLine.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LaserDrivenBeamLine.cc
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"
43 #include "LaserDrivenBeamLine.hh"
45 //
46 #include "G4PhysicalConstants.hh"
47 #include "G4ThreeVector.hh"
48 #include "G4Material.hh"
49 //
50 #include "G4FieldManager.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 //
76 #include "G4ElectricField.hh"
78 
80 //
81 //G4bool LaserDrivenBeamLine::doCalculation = false;
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 {
103 
104  //***************************** PW ***************************************
105 
106  static G4String ROGeometryName = "DetectorROGeometry";
107  RO = new HadrontherapyDetectorROGeometry(ROGeometryName);
108 
109  G4cout << "Going to register Parallel world...";
111  G4cout << "... done" << G4endl;
112  //***************************** PW ***************************************
113 }
114 
117 {
118  //delete laserDrivenMessenger;
120 }
121 
124 {
125  // Sets default geometry and materials
127 
128  // Construct the energyselector (magnetic part and slit) and detector plane
130 
131  //***************************** PW ***************************************
133 
134  //***************************** PW ***************************************
135 
136  // HadrontherapyDetectorConstruction builds ONLY the phantom and the detector with its associated ROGeometry
138  G4cout<<"HadrontherapyDetectorConstruction"<<G4endl;
139  //***************************** PW ***************************************
140 
142 
143  //***************************** PW ***************************************
144  return physicTreatmentRoom;
145 }
148 {
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.
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;
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;
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;
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;
302  // The Final Collimator is located after the 4th magnet
303  G4double defaultExitholeToFinalCollimator=70 *mm;
304  ExitholeToFinalCollimator=defaultExitholeToFinalCollimator;
305 
308 
311 
314 
317 
320 
323  FinalcollimatorXPosition = 0.0*mm; //HOLE IN THE FINAL COLLIMATOR
324 
328 
332 
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 
372  Magnet_4YPosition=0.0*mm;
373  Magnet_4ZPosition=(defaultExternalMagnet_ZSize+defaultMagnet_ZSize)/2.;
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 
395  Magnet_3YPosition=0.0*mm;
396  Magnet_3ZPosition=(defaultExternalMagnet_ZSize+defaultMagnet_ZSize)/2.;
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 
417  Magnet_2YPosition=0.0*mm;
418  Magnet_2ZPosition=(defaultExternalMagnet_ZSize+defaultMagnet_ZSize)/2.;
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  //
484 
487 
489 
492 
495 
496  G4double defultMagnet1ToFirstCollimator=25.*mm;
497  Magnet1ToFirstCollimator=defultMagnet1ToFirstCollimator;
498 
501  collimatorXPosition = 0.0*mm;
502 
505  collimatorYPosition = 0.0*mm;
506 
509  collimatorZPosition = 0.*mm;
510 
511  collimatorBoxYSize=82.0* mm;
512  collimatorBoxZSize=210.0* mm;
513 
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 
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 
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 
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;
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;
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;
695 
696 }
697 
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 
716  "logicTreatmentRoom",
717  0,
718  0,
719  0);
720 
722  G4ThreeVector(),
723  "physicalTreatmentRoom",
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
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 
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....
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);
797  pIntgrDriver = new G4MagInt_Driver(1*mm,fstepper,fstepper-> GetNumberOfVariables());
798  //the first parameter is the minimum step
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....
808  PurgMagFieldQuadFourth = new HadrontherapyMagneticField3D("field/Quad80MagneticField.TABLE", xOffsetFQ);
810  pFieldMgrQuadFourth -> SetDetectorField(PurgMagFieldQuadFourth);
811 
812  pFieldMgrQuadFourth -> CreateChordFinder(PurgMagFieldQuadFourth);
816  //the first parameter is the minimum step
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....
825  PurgMagFieldQuadThird = new HadrontherapyMagneticField3D("field/Quad40MagneticField.TABLE", xOffsetTQ);
827  pFieldMgrQuadThird -> SetDetectorField(PurgMagFieldQuadThird);
828  pFieldMgrQuadThird -> CreateChordFinder(PurgMagFieldQuadThird);
832  //the first parameter is the minimum step
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....
841  PurgMagFieldQuadSecond = new HadrontherapyMagneticField3D("field/Quad40MagneticField.TABLE", xOffsetSQ);
843  pFieldMgrQuadSecond -> SetDetectorField(PurgMagFieldQuadSecond);
844  pFieldMgrQuadSecond -> CreateChordFinder(PurgMagFieldQuadSecond);
848  //the first parameter is the minimum step
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....
857  PurgMagFieldQuadFirst = new HadrontherapyMagneticField3D("field/Quad80MagneticField.TABLE", xOffsetFirstQ);
859  pFieldMgrQuadFirst -> SetDetectorField(PurgMagFieldQuadFirst);
860  pFieldMgrQuadFirst -> CreateChordFinder(PurgMagFieldQuadFirst);
864  //the first parameter is the minimum step
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 
907 {
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 
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 
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 
949  "LVirtualMag",
950  0,0,0);
952  G4ThreeVector(virtualMagPosX, 0.*cm, 0*mm),
953  "PVirtualMag",
956  true, 0);
957 
958 
959  logicVirtualMag -> SetVisAttributes(blue);
960 
962 
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,
977  "LBeveledCylinder",
978  0,0,0);
979 
981  "physicBeveledCylinder",
984  true,0);
985 
987 
988 
990 
991  KaptonEntranceWindow= new G4Tubs("KaptonEntranceWindow",
992  0,
993  OuterRadiusFC,
994  KaptonEntranceWindowThickness/2,
995  0*deg,360*deg);
996 
998  // internalChamberMaterial, for track control
1000  "LKaptonEntranceWindow",
1001  0,0,0);
1002 
1003  physicKaptonEntranceWindow=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(KaptonEntranceWindowPosX,0,0)),
1004  "PhysicEntranceWindow",
1006  physicVirtualMag,true,0);
1007  logicKaptonEntranceWindow -> SetVisAttributes(gray);
1008 
1010 
1011  MassRing=new G4Tubs ("MassRing",
1012  InnerRadiusFC,
1013  OuterRadiusFC,
1014  MassRingThickness/2,
1015  0*deg,360*deg);
1016 
1019  "logicMassRing",
1020  0,0,0);
1021 
1022  physicMassRing=new G4PVPlacement( G4Transform3D(rm,G4ThreeVector(MassRingPosX,0,0)),
1023 
1024  "PhysicMassRing",logicMassRing,
1025 
1027  true,0);
1028  logicMassRing -> SetVisAttributes(green);
1029 
1030 
1031 
1032 
1034 
1035 
1036  VirtualWindow=new G4Tubs("VirtualWindow",
1037  0,
1038  OuterRadiusFC,
1039  VirtualWindowThickness/2,
1040  0*deg,360*deg);
1041 
1044  "logicVirtualWindow",
1045  0,0,0);
1046 
1047  physicVirtualWindow=new G4PVPlacement( G4Transform3D(rm,G4ThreeVector(VirtualWindowPosX,0,0)),
1048 
1049  "PhysicVirtualWindow",
1052  true,0);
1054 
1056 
1057  GuardRing=new G4Tubs ("GuardRing",
1058  InnerRadiusFC,
1059  OuterRadiusFC,
1060  GuardRingThickness/2,
1061  0*deg,360*deg);
1062 
1065  "logicGuardRing",
1066  0,0,0);
1067 
1068  physicGuardRing=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(GuardRingPosX,0,0)),
1069 
1070  "PhysicGuardRing", logicGuardRing,
1071 
1073  true,0);
1074  logicGuardRing -> SetVisAttributes(red);
1075 
1076 
1078 
1079 
1080  VirtualMiddle=new G4Tubs ("VirtualMiddle",
1081  0,
1082  OuterRadiusFC,
1083  VirtualMiddleThickness/2,
1084  0*deg,360*deg);
1085 
1088  "logicVirtualMiddle",
1089  0,0,0);
1090 
1091  physicVirtualMiddle=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualMiddlePosX,0,0)),
1092 
1093  "PhysicVirtualMiddle", logicVirtualMiddle,
1094 
1096  true,0);
1097 
1099 
1101 
1102  FaradayCupBottom=new G4Tubs ("FaradayCupBottom",
1103  InnerRadiusFC,
1104  OuterRadiusFC,
1105  FaradayCupBottomThickness/2,
1106  0*deg,360*deg);
1107 
1110  "logicFaradayCupBottom",
1111  0,0,0);
1112 
1113  physicFaradayCupBottom=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(FaradayCupBottomPosX,0,0)),
1114  "PhysicFaradayCupBottom",logicFaradayCupBottom,
1116  true,0);
1117  logicFaradayCupBottom -> SetVisAttributes(yellow);
1118 
1119 
1121 
1122  VirtualBottom=new G4Tubs ("VirtualBottom",
1123  0,
1124  OuterRadiusFC,
1125  VirtualBottomThickness/2,
1126  0*deg,360*deg);
1127 
1130  "logicVirtualBottom",
1131  0,0,0);
1132 
1133  physicVirtualBottom=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualBottomPosX,0,0)),
1134  "PhysicVirtualBottom",
1137  true,0);
1138 
1140 
1142 
1143  Cup=new G4Tubs ("Cup",
1144  0,
1145  OuterRadiusFC,
1146  CupThickness/2,
1147  0*deg,360*deg);
1148 
1150  CupMaterial,
1151  "logicCup",
1152  0,0,0);
1153 
1154  physicCup=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(CupPosX,0,0)),
1155  "PhysicCup", logicCup,
1156 
1158  true,0);
1159 
1160  logicCup -> SetVisAttributes(darkGreen);
1161 
1162 
1164 
1165  VirtualOverBottom=new G4Tubs ("VirtualOverBottom",
1166  0,
1167  OuterRadiusFC,
1168  VirtualOverBottomThickness/2,
1169  0*deg,360*deg);
1170 
1173  "logicVirtualOverBottom",
1174  0,0,0);
1175 
1176  physicVirtualOverBottom=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualOverBottomPosX,0,0)),
1177  "PhysicVirtualOverBottom",logicVirtualOverBottom,
1178 
1180  true,0);
1182 
1183 
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 
1195  "logicVirtualLateral",
1196  0,0,0);
1197 
1198  physicVirtualLateral=new G4PVPlacement(G4Transform3D(rm,G4ThreeVector(VirtualLateralPosX,0,0)),
1199  "VirtualLateral",logicVirtualLateral,
1200 
1202  true,0);
1203 
1204 
1205 
1207 }
1208 
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 
1218 
1220 
1222  "physQuadChamberWall", LQuadChamberWall,physicTreatmentRoom, false, 0);
1223 
1224 
1226 
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);
1237 
1239 
1241  "PhysFourthTQuad", LFourthTriplet, PQuadChamber, false, 0);
1242 
1245 
1246  logicFourthQuad = new G4LogicalVolume(solidFourthQuad, QuadMaterial, "LogicQuad", 0, 0, 0);
1247 
1249  "PhysFourthQuad",logicFourthQuad, PFourthTriplet, false, 0);
1250 
1251  LFourthTriplet -> SetVisAttributes(yellow);
1252  logicFourthQuad -> SetVisAttributes(green);
1256 
1257  LThirdTriplet = new G4LogicalVolume(SThirdTriplet, internalChamberMaterial,"LogicTTQuad", 0, 0, 0);
1258 
1260  "PhysThirdTQuad",LThirdTriplet,PQuadChamber, false, 0);
1261 
1264 
1265  logicThirdQuad = new G4LogicalVolume(solidThirdQuad, QuadMaterial, "LogicTQuad", 0, 0, 0);
1266 
1268  "PhysThirdQuad",logicThirdQuad, PThirdTriplet, false, 0);
1269 
1270  LThirdTriplet -> SetVisAttributes(yellow);
1271  logicThirdQuad -> SetVisAttributes(green);
1275 
1277 
1279  "PhysSecondTQuad", LSecondTriplet, PQuadChamber, false, 0);
1280 
1283 
1284  logicSecondQuad = new G4LogicalVolume(solidSecondQuad, QuadMaterial, "LogicSQuad", 0, 0, 0);
1285 
1287  "PhysSecondQuad", logicSecondQuad, PSecondTriplet, false, 0);
1288 
1289  LSecondTriplet -> SetVisAttributes(yellow);
1290  logicSecondQuad -> SetVisAttributes(green);
1294 
1296 
1298  "PhysFirstTQuad", LFirstTriplet, PQuadChamber, false, 0);
1299 
1302 
1303  logicFirstQuad = new G4LogicalVolume(solidFirstQuad, QuadMaterial, "LogicQuad", 0, 0, 0);
1304 
1306  "PhysFirstQuad",logicFirstQuad, PFirstTriplet, false, 0);
1307 
1308  LFirstTriplet -> SetVisAttributes(yellow);
1309  logicFirstQuad -> SetVisAttributes(green);
1310 }
1311 
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",
1322  externalChamberZSize/2.0);
1323 
1326  "ExternalChamber");
1327 
1332  "ExternalChamber",
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",
1345  internalChamberZSize/2.0);
1346 
1349  "LInternalChamber");
1350 
1352  G4ThreeVector(0,0,0),
1353  "InternalChamber",
1356  false,
1357  0);
1358  logicInternalChamber -> SetVisAttributes(white);
1359 }
1360 
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",
1372  EntrancePipeheight/2.,
1375 
1377  PipeMaterial,
1378  "EntrancePipe",
1379  0,
1380  0,
1381  0);
1382 
1387  "EntrancePipe",
1390  false,
1391  0);
1392 
1393  logicEntrancePipe -> SetVisAttributes(red);
1394 
1395 }
1396 
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",
1411 
1414  "Entrancehole",
1415  0,
1416  0,
1417  0);
1418  //the hole in the energy selector chamber
1423  "Entrancehole",
1426  false,
1427  0);
1428  //the hole in the quadrupoles chamber
1433  "EntranceholeQuad",
1436  false,
1437  0);
1438 
1439  logicEntrancehole -> SetVisAttributes(skyBlue);
1440 
1441 
1442 }
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 
1458  "collimator");
1459 
1464  "collimator",
1467  false,
1468  0);
1469 
1470  logicCollimator -> SetVisAttributes(darkOrange3);
1471 
1472  solidCollimatorHole = new G4Tubs("CollimatorHole",
1478 
1481  "CollimatorHole",
1482  0,
1483  0,
1484  0);
1485 
1490  "CollimatorHole",
1493  false,
1494  0);
1495 
1496  logicCollimatorHole -> SetVisAttributes(skyBlue);
1497 }
1498 
1500 // Magnet number 1
1502 { // The positions of the external and internal partes are given as respect the external chamber.
1503  solidExternalMagnet_1 = new G4Box("SolidExternalMagnet_1",
1506  externalMagnet_1ZSize/2.0);
1507 
1510  "LogicExternalMagnet_1");
1511 
1516  "PhysicExternalMagnet_1",
1519  false,
1520  0);
1525  "PhysicExternalMagnet_1Down",
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 
1542  "LogicMagnet_1");
1543 
1547  "PhysicMagnet_1Right",
1548  logicMagnet_1,
1550  false,
1551  0);
1555  "PhysicMagnet_1Left",
1556  logicMagnet_1,
1558  false,
1559  0);
1560 
1561  logicMagnet_1 -> SetVisAttributes(gray);
1562 }
1563 
1565 // Magnet number 2
1567 { // The position of the external part are given as respect the external chamber.
1568 
1569  solidExternalMagnet_2 = new G4Box("SolidExternalMagnet_2",
1572  externalMagnet_2ZSize/2.0);
1573 
1576  "LogicExternalMagnet_2");
1577 
1582  "PhysicExternalMagnet_2",
1585  false,
1586  0);
1587 
1592  "PhysicExternalMagnet_2Down",
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 
1609  "LogicMagnet_2");
1610 
1613  (Magnet_2ZPosition)+32*mm),
1614  "PhysicMagnet_2Right",
1615  logicMagnet_2,
1617  false,
1618  0);
1621  (-(Magnet_2ZPosition)+32*mm)),
1622  "PhysicMagnet_2Left",
1623  logicMagnet_2,
1625  false,
1626  0);
1627  logicMagnet_2 -> SetVisAttributes(gray);
1628 }
1629 
1631 // Magnet number 3
1633 { // The position of the external part are given as respect the external chamber.
1634 
1635  solidExternalMagnet_3 = new G4Box("SolidExternalMagnet_3",
1638  externalMagnet_3ZSize/2.0);
1639 
1642  "LogicExternalMagnet_3");
1643 
1648  "PhysicExternalMagnet_3",
1651  false,
1652  0);
1653 
1658  "PhysicExternalMagnet_3Down",
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 
1674  "LogicMagnet_3");
1675 
1678  (Magnet_3ZPosition+32*mm)),
1679  "PhysicMagnet_3Right",
1680  logicMagnet_3,
1682  false,
1683  0);
1686  (-(Magnet_3ZPosition)+32*mm)),
1687  "PhysicMagnet_3Left",
1688  logicMagnet_3,
1690  false,
1691  0);
1692  logicMagnet_3 -> SetVisAttributes(gray);
1693 
1694 }
1695 
1697 // Magnet number 4
1699 { // The position of the external part are given as respect the external chamber.
1700 
1701  solidExternalMagnet_4 = new G4Box("SolidExternalMagnet_4",
1704  externalMagnet_4ZSize/2.0);
1705 
1708  "LogicExternalMagnet_4");
1709 
1714  "PhysicExternalMagnet_4",
1717  false,
1718  0);
1719 
1724  "PhysicExternalMagnet_4Down",
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 
1740  "LogicMagnet_4");
1741 
1745  "PhysicMagnet_4Right",
1746  logicMagnet_4,
1748  false,
1749  0);
1753  "PhysicMagnet_4Left",
1754  logicMagnet_4,
1756  false,
1757  0);
1758  logicMagnet_4 -> SetVisAttributes(gray);
1759 }
1760 
1762 // Slit
1764 {
1765  solidExternalSlit = new G4Box("ExternalSlit",
1766  externalSlitXSize/2.0,
1767  externalSlitYSize/2.0,
1768  externalSlitZSize/2.0);
1769 
1772  "ExternalSlit");
1773 
1778  "ExternalSlit",
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 
1793  "InternalSlit");
1794 
1799  "InternalSlit",
1802  false,
1803  0);
1804 
1805  logicInternalSlit -> SetVisAttributes(skyBlue);
1806 
1807 }
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",
1820 
1823  "collimatorFinal");
1824 
1829  "collimatorFinal",
1832  false,
1833  0);
1834  logicFinalCollimator -> SetVisAttributes(darkOrange3);
1835 
1836  solidFinalCollimatorHole= new G4Tubs("FinalCollimatorHole",
1842 
1845  "FinalCollimatorHole",
1846  0,
1847  0,
1848  0);
1849 
1854  "FinalCollimatorHole",
1857  false,
1858  0);
1859  logicFinalCollimatorHole -> SetVisAttributes(skyBlue);
1860 }
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",
1875 
1878  "ExitWindow",
1879  0,
1880  0,
1881  0);
1882 
1887  "ExitWindow",
1890  false,
1891  0);
1892 
1893  logicExitWindow -> SetVisAttributes(skyBlue);
1894 
1895 }
1896 
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",
1908  ExitPipeheight/2.,
1911 
1913  PipeMaterial,
1914  "ExitPipe",
1915  0,
1916  0,
1917  0);
1918 
1923  "ExitPipe",
1924  logicExitPipe,
1926  false,
1927  0);
1928 
1929  logicExitPipe -> SetVisAttributes(red);
1930 
1931 }
1932 
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",
1944  ExitholeThickness/2.,
1947 
1950  "Exithole",
1951  0,
1952  0,
1953  0);
1954 
1959  "Exithole",
1960  logicExithole,
1962  false,
1963  0);
1964 
1965  logicExithole -> SetVisAttributes(skyBlue);
1966 
1967 }
1970 // Disable via external macro command the Energy Selector System
1972 {
1982  if(physicCollimator) {delete physicCollimator; delete logicCollimator; delete solidCollimator; }
1987  if(physicExithole){delete physicExithole; delete logicExithole; delete solidExithole;}
1989  if(physicExitPipe){delete physicExitPipe; delete logicExitPipe; delete solidExitPipe;}
1993  if(pFieldMgr) {delete pFieldMgr;}
1994 
1995 
1996 
1997  G4cout << "****************************************************" << G4endl;
1998  G4cout << "************ The ESS has been disabled *************" << G4endl;
1999  G4cout << "****************************************************" << G4endl;
2001 
2002  G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2003 
2004 }
2005 // Change via external macro command the diameter of the first collimator
2007 {
2008  G4double radius = valueR;
2009  solidCollimatorHole -> SetOuterRadius(radius);
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 }
2017 // Change via external macro command the thickness of the first collimator
2019 {
2020  G4double thickness = valueC/2;
2021  solidCollimator -> SetXHalfLength(thickness);
2022  solidCollimatorHole -> SetZHalfLength(thickness);
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
2032 {
2033  physicCollimatorHole -> SetTranslation(G4ThreeVector(0., 0., valueQ));
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
2043 {
2044  G4double radius = value;
2045  solidFinalCollimatorHole -> SetOuterRadius(radius);
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 
2054 // Change via external macro command the thickness of the second collimator
2056 {
2057  G4double thickness = value/2;
2058  solidFinalCollimator -> SetXHalfLength(thickness);
2059  solidFinalCollimatorHole -> SetZHalfLength(thickness);
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
2069 {
2070  physicFinalCollimatorHole -> SetTranslation(G4ThreeVector(0., 0., value));
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
2079 // Change the thickness of the Slit
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);
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 }
2105 // Change the hole size (in Y direction) of the Slit
2107 {
2108  G4double hole = value/2;
2109  solidInternalSlit -> SetYHalfLength(hole);
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 
2118 // Change the hole size (in Z direction) of the Slit
2120 {
2121  G4double hole = value/2;
2122  solidInternalSlit -> SetZHalfLength(hole);
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 }
2130 // Change the Z position of the hole of the Slit
2132 {
2133  physicInternalSlit -> SetTranslation(G4ThreeVector(0., 0., value));
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
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;}
2158 
2159 
2160  G4cout << "******************************************************************" << G4endl;
2161  G4cout << "************ The Quadrupoles system has been disabled *************" << G4endl;
2162  G4cout << "******************************************************************" << G4endl;
2164 
2165  G4UImanager::GetUIpointer() -> ApplyCommand("/vis/viewer/flush");
2166 
2167 }
2168