File indexing completed on 2025-01-31 09:22:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 #include <cmath>
0042 #include "G4SystemOfUnits.hh"
0043 #include "globals.hh"
0044 #include "G4SDManager.hh"
0045 #include "G4RunManager.hh"
0046 #include "G4GeometryManager.hh"
0047 #include "G4SolidStore.hh"
0048 #include "G4PhysicalVolumeStore.hh"
0049 #include "G4LogicalVolumeStore.hh"
0050 #include "G4Box.hh"
0051 #include "G4LogicalVolume.hh"
0052 #include "G4ThreeVector.hh"
0053 #include "G4PVPlacement.hh"
0054 #include "G4Transform3D.hh"
0055 #include "G4RotationMatrix.hh"
0056 #include "G4Colour.hh"
0057 #include "G4UserLimits.hh"
0058 #include "G4UnitsTable.hh"
0059 #include "G4VisAttributes.hh"
0060 #include "G4NistManager.hh"
0061 #include "IORTDetectorConstruction.hh"
0062 #include "G4Tubs.hh"
0063 #include "G4MultiFunctionalDetector.hh"
0064 #include "G4VPrimitiveScorer.hh"
0065 #include "G4PSDoseDeposit3D.hh"
0066 #include "IORTDetectorMessenger.hh"
0067
0068
0069 IORTDetectorConstruction::IORTDetectorConstruction(G4VPhysicalVolume* physicalTreatmentRoom)
0070 : motherPhys(physicalTreatmentRoom),
0071 phantom(0), detector(0),
0072 phantomLogicalVolume(0), detectorLogicalVolume(0),
0073 phantomPhysicalVolume(0), detectorPhysicalVolume(0),
0074 aRegion(0),
0075
0076 solidDiscoIORT0(0),
0077 logicDiscoIORT0(0),
0078 physiDiscoIORT0(0),
0079
0080 solidDiscoIORT(0),
0081 logicDiscoIORT(0),
0082 physiDiscoIORT(0),
0083
0084 solidDiscoIORT1(0),
0085 logicDiscoIORT1(0),
0086 physiDiscoIORT1(0)
0087
0088 {
0089
0090
0091
0092
0093
0094
0095
0096
0097 detectorMessenger = new IORTDetectorMessenger(this);
0098
0099
0100 SetPhantomMaterial("G4_WATER");
0101
0102
0103
0104
0105
0106 detectorSizeX = 7.* cm;
0107 detectorSizeY = 15.* cm;
0108 detectorSizeZ = 15.* cm;
0109
0110 SetDetectorSize(detectorSizeX, detectorSizeY, detectorSizeZ);
0111
0112
0113 SetPhantomSize(20. *cm, 20. *cm, 20. *cm);
0114 SetPhantomPosition(G4ThreeVector(4.5 *cm, 0. *cm, 0. *cm));
0115 SetDetectorToPhantomPosition(G4ThreeVector(0. *cm, 2.5 *cm, 2.5 *cm));
0116
0117
0118 SetOuterRadiusDiscoIORT (40. *mm);
0119 SetinnerRadiusDiscoIORT (0.*mm);
0120 SetheightDiscoIORT (2.0*mm);
0121 SetDiscoXPositionIORT (-11.0*mm);
0122 SetDiscoYPositionIORT (0.0*mm);
0123 SetDiscoZPositionIORT (0.0*mm);
0124 SetDiscoMaterialIORT("G4_WATER");
0125
0126 SetOuterRadiusDiscoIORT1 (40. *mm);
0127 SetinnerRadiusDiscoIORT1 (0.*mm);
0128 SetheightDiscoIORT1 (1.0*mm);
0129 SetDiscoXPositionIORT1 (-8.0*mm);
0130 SetDiscoMaterialIORT1("G4_WATER");
0131
0132 SetAngleDiscoIORT0 (90.0 *deg);
0133
0134
0135 UpdateGeometry();
0136 }
0137
0138
0139 IORTDetectorConstruction::~IORTDetectorConstruction()
0140 {
0141 delete detectorMessenger;
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151 void IORTDetectorConstruction::ConstructPhantom()
0152 {
0153
0154 phantom = new G4Box("Phantom",
0155 phantomSizeX/2,
0156 phantomSizeY/2,
0157 phantomSizeZ/2);
0158
0159
0160 phantomLogicalVolume = new G4LogicalVolume(phantom,
0161 phantomMaterial,
0162 "phantomLog", 0, 0, 0);
0163
0164
0165 phantomPhysicalVolume = new G4PVPlacement(0,
0166 phantomPosition,
0167 "phantomPhys",
0168 phantomLogicalVolume,
0169 motherPhys,
0170 false,
0171 0);
0172
0173
0174 red = new G4VisAttributes(G4Colour(255/255., 0/255. ,0/255.));
0175 red -> SetVisibility(true);
0176
0177
0178 phantomLogicalVolume -> SetVisAttributes(red);
0179
0180 }
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 void IORTDetectorConstruction::ConstructDetector()
0206 {
0207
0208
0209 detector = new G4Box("Detector",
0210 detectorSizeX/2,
0211 detectorSizeY/2,
0212 detectorSizeZ/2);
0213
0214
0215 detectorLogicalVolume = new G4LogicalVolume(detector,
0216 detectorMaterial,
0217 "DetectorLog",
0218 0,0,0);
0219
0220 detectorPhysicalVolume = new G4PVPlacement(0,
0221 detectorPosition,
0222 "DetectorPhys",
0223 detectorLogicalVolume,
0224 phantomPhysicalVolume,
0225 false,0);
0226
0227
0228
0229 G4VisAttributes * skyBlue1 = new G4VisAttributes( G4Colour(135/255. , 206/255. , 235/255. ));
0230 detectorLogicalVolume -> SetVisAttributes(skyBlue1);
0231
0232
0233
0234
0235
0236
0237
0238 if (!aRegion)
0239 {
0240 aRegion = new G4Region("DetectorLog");
0241 detectorLogicalVolume -> SetRegion(aRegion);
0242 aRegion -> AddRootLogicalVolume(detectorLogicalVolume);
0243 }
0244 G4cout << "The Detector has been built --- Add a scoring mesh for it in the GUI if appropriate (similar to the phantom one)" << G4endl;
0245
0246 }
0247
0248 void IORTDetectorConstruction::ConstructDisc()
0249 {
0250
0251
0252
0253 const G4double startAngleDiscoIORT0 = 0.*deg;
0254 const G4double spanningAngleDiscoIORT0 = 360.*deg;
0255
0256
0257 G4RotationMatrix rm0;
0258 rm0.rotateY(AngleDiscoIORT0);
0259
0260
0261 solidDiscoIORT0 = new G4Tubs("DiscoIORT0", innerRadiusDiscoIORT,
0262 OuterRadiusDiscoIORT,
0263 (heightDiscoIORT + heightDiscoIORT1),
0264 startAngleDiscoIORT0,
0265 spanningAngleDiscoIORT0);
0266
0267 G4LogicalVolume* logDiscoIORT0 = new G4LogicalVolume(solidDiscoIORT0,
0268 detectorMaterial, "DiscoIORT0Log", 0, 0, 0);
0269
0270 physiDiscoIORT0 = new G4PVPlacement(G4Transform3D(rm0, G4ThreeVector((DiscoXPositionIORT + heightDiscoIORT1),DiscoYPositionIORT,DiscoZPositionIORT)),
0271 "DiscoIORT0Phys", logDiscoIORT0, detectorPhysicalVolume, false, 0);
0272
0273 white = new G4VisAttributes( G4Colour());
0274 white -> SetVisibility(true);
0275
0276 logDiscoIORT0 -> SetVisAttributes(white);
0277
0278
0279
0280
0281
0282
0283
0284 gray = new G4VisAttributes( G4Colour(0.5, 0.5, 0.5 ));
0285 gray-> SetVisibility(true);
0286
0287
0288
0289 gray1 = new G4VisAttributes( G4Colour(0.7, 0.7, 0.7 ));
0290 gray1-> SetVisibility(true);
0291
0292
0293
0294 const G4double startAngleDiscoIORT = 0.*deg;
0295 const G4double spanningAngleDiscoIORT = 360.*deg;
0296
0297 G4double phi = 0. *deg;
0298
0299
0300 G4RotationMatrix rm;
0301 rm.rotateY(phi);
0302
0303 solidDiscoIORT = new G4Tubs("DiscoIORT", innerRadiusDiscoIORT,
0304 OuterRadiusDiscoIORT,
0305 heightDiscoIORT,
0306 startAngleDiscoIORT,
0307 spanningAngleDiscoIORT);
0308
0309 G4LogicalVolume* logDiscoIORT = new G4LogicalVolume(solidDiscoIORT,
0310 DiscoMaterialIORT, "DiscoIORTLog", 0, 0, 0);
0311
0312 physiDiscoIORT = new G4PVPlacement(G4Transform3D(rm, G4ThreeVector(0.,0.,(- heightDiscoIORT1))),
0313 "DiscoIORTPhys", logDiscoIORT, physiDiscoIORT0, false, 0);
0314
0315 logDiscoIORT -> SetVisAttributes(gray1);
0316
0317
0318
0319
0320
0321
0322 const G4double startAngleDiscoIORT1 = 0.*deg;
0323 const G4double spanningAngleDiscoIORT1 = 360.*deg;
0324
0325 solidDiscoIORT1 = new G4Tubs("DiscoIORT1", innerRadiusDiscoIORT1,
0326 OuterRadiusDiscoIORT1,
0327 heightDiscoIORT1,
0328 startAngleDiscoIORT1,
0329 spanningAngleDiscoIORT1);
0330
0331 G4LogicalVolume* logDiscoIORT1 = new G4LogicalVolume(solidDiscoIORT1,
0332 DiscoMaterialIORT1, "DiscoIORTLog1", 0, 0, 0);
0333
0334 physiDiscoIORT1 = new G4PVPlacement(G4Transform3D(rm, G4ThreeVector(0.,0.,heightDiscoIORT)),
0335 "DiscoIORTPhys1", logDiscoIORT1, physiDiscoIORT0, false, 0);
0336 white = new G4VisAttributes( G4Colour());
0337 white -> SetVisibility(true);
0338 white -> SetForceSolid(true);
0339 logDiscoIORT1 -> SetVisAttributes(gray);
0340
0341 }
0342
0343
0344 void IORTDetectorConstruction::ParametersCheck()
0345 {
0346
0347 if (!IsInside(detectorSizeX,
0348 detectorSizeY,
0349 detectorSizeZ,
0350 phantomSizeX,
0351 phantomSizeY,
0352 phantomSizeZ,
0353 detectorToPhantomPosition
0354 ))
0355 G4Exception("IORTDetectorConstruction::ParametersCheck()", "IORT0001", FatalException, "Error: Detector is not fully inside Phantom!");
0356 }
0357
0358
0359
0360
0361
0362 G4bool IORTDetectorConstruction::SetPhantomMaterial(G4String material)
0363 {
0364
0365 if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
0366 {
0367 phantomMaterial = pMat;
0368 detectorMaterial = pMat;
0369 if (detectorLogicalVolume && phantomLogicalVolume)
0370 {
0371 detectorLogicalVolume -> SetMaterial(pMat);
0372 phantomLogicalVolume -> SetMaterial(pMat);
0373
0374 G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0375 G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0376 G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl;
0377 }
0378 }
0379 else
0380 {
0381 G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0382 " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl;
0383 G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl;
0384 return false;
0385 }
0386
0387 return true;
0388 }
0389
0390 G4bool IORTDetectorConstruction::SetDiscoMaterialIORT(G4String material)
0391 {
0392
0393 if (G4Material* dMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
0394 {
0395 DiscoMaterialIORT = dMat;
0396
0397 if (logicDiscoIORT)
0398 {
0399 logicDiscoIORT -> SetMaterial(dMat);
0400
0401 G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0402 G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0403 G4cout << "The material of Protection disc 1 has been changed to " << material << G4endl;
0404 }
0405 }
0406 else
0407 {
0408 G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0409 " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl;
0410 G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl;
0411 return false;
0412 }
0413
0414 return true;
0415 }
0416
0417 G4bool IORTDetectorConstruction::SetDiscoMaterialIORT1(G4String material)
0418 {
0419
0420 if (G4Material* d1Mat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) )
0421 {
0422 DiscoMaterialIORT1 = d1Mat;
0423
0424 if (logicDiscoIORT1)
0425 {
0426 logicDiscoIORT1 -> SetMaterial(d1Mat);
0427
0428 G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0429 G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0430 G4cout << "The material of Protection disc 2 has been changed to " << material << G4endl;
0431 }
0432 }
0433 else
0434 {
0435 G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0436 " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl;
0437 G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl;
0438 return false;
0439 }
0440
0441 return true;
0442 }
0443
0444 void IORTDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ)
0445 {
0446 if (sizeX > 0.) phantomSizeX = sizeX;
0447 if (sizeY > 0.) phantomSizeY = sizeY;
0448 if (sizeZ > 0.) phantomSizeZ = sizeZ;
0449 }
0450
0451
0452 void IORTDetectorConstruction::SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ)
0453 {
0454 if (sizeX > 0.) {detectorSizeX = sizeX;}
0455 if (sizeY > 0.) {detectorSizeY = sizeY;}
0456 if (sizeZ > 0.) {detectorSizeZ = sizeZ;}
0457 }
0458
0459
0460 void IORTDetectorConstruction::SetVoxelSize(G4double , G4double , G4double)
0461 {
0462 G4cout<< "SetVoxelSize method is not needed anymore " << G4endl;
0463 }
0464 void IORTDetectorConstruction::SetPhantomPosition(G4ThreeVector pos)
0465 {
0466 phantomPosition = pos;
0467 }
0468
0469
0470 void IORTDetectorConstruction::SetDetectorToPhantomPosition(G4ThreeVector displ)
0471 {
0472 detectorToPhantomPosition = displ;
0473 }
0474
0475
0476 void IORTDetectorConstruction::SetOuterRadiusDiscoIORT(G4double outerr)
0477 {
0478 if (outerr > 0.) {OuterRadiusDiscoIORT = outerr;}
0479
0480 }
0481
0482 void IORTDetectorConstruction::SetinnerRadiusDiscoIORT(G4double innerr)
0483 {
0484 if (innerr >= 0.) {innerRadiusDiscoIORT = innerr;}
0485
0486 }
0487
0488 void IORTDetectorConstruction::SetheightDiscoIORT(G4double height)
0489 {
0490 if (height > 0.) {heightDiscoIORT = height;}
0491
0492 }
0493
0494 void IORTDetectorConstruction::SetDiscoXPositionIORT(G4double xpos)
0495 {
0496
0497 DiscoXPositionIORT = xpos;
0498
0499 }
0500
0501 void IORTDetectorConstruction::SetDiscoYPositionIORT(G4double ypos)
0502 {
0503
0504 DiscoYPositionIORT = ypos;
0505
0506 }
0507
0508 void IORTDetectorConstruction::SetDiscoZPositionIORT(G4double zpos)
0509 {
0510
0511 DiscoZPositionIORT = zpos;
0512
0513 }
0514
0515 void IORTDetectorConstruction::SetOuterRadiusDiscoIORT1(G4double outerr)
0516 {
0517 if (outerr > 0.) {OuterRadiusDiscoIORT1 = outerr;}
0518
0519 }
0520
0521 void IORTDetectorConstruction::SetinnerRadiusDiscoIORT1(G4double innerr)
0522 {
0523 if (innerr >= 0.) {innerRadiusDiscoIORT1 = innerr;}
0524
0525 }
0526
0527 void IORTDetectorConstruction::SetheightDiscoIORT1(G4double height)
0528 {
0529 if (height > 0.) {heightDiscoIORT1 = height;}
0530
0531 }
0532
0533 void IORTDetectorConstruction::SetDiscoXPositionIORT1(G4double xpos)
0534 {
0535
0536 DiscoXPositionIORT1 = xpos;
0537 }
0538
0539 void IORTDetectorConstruction::SetAngleDiscoIORT0(G4double phi0)
0540 {
0541
0542 AngleDiscoIORT0 = phi0;
0543 }
0544
0545
0546
0547
0548
0549 void IORTDetectorConstruction::UpdateGeometry()
0550 {
0551
0552
0553
0554 ParametersCheck();
0555
0556 G4GeometryManager::GetInstance() -> OpenGeometry();
0557 if (phantom)
0558 {
0559 phantom -> SetXHalfLength(phantomSizeX/2);
0560 phantom -> SetYHalfLength(phantomSizeY/2);
0561 phantom -> SetZHalfLength(phantomSizeZ/2);
0562 phantomPhysicalVolume -> SetTranslation(phantomPosition);
0563 }
0564 else ConstructPhantom();
0565
0566
0567 SetDetectorPosition();
0568 if (detector)
0569 {
0570 detector -> SetXHalfLength(detectorSizeX/2);
0571 detector -> SetYHalfLength(detectorSizeY/2);
0572 detector -> SetZHalfLength(detectorSizeZ/2);
0573 detectorPhysicalVolume -> SetTranslation(detectorPosition);
0574 }
0575 else ConstructDetector();
0576
0577
0578 if (physiDiscoIORT1) delete physiDiscoIORT1;
0579 if (logicDiscoIORT1) delete logicDiscoIORT1;
0580 if (solidDiscoIORT1) delete solidDiscoIORT1;
0581
0582 if (physiDiscoIORT) delete physiDiscoIORT;
0583 if (logicDiscoIORT) delete logicDiscoIORT;
0584 if (solidDiscoIORT) delete solidDiscoIORT;
0585
0586 if (physiDiscoIORT0) delete physiDiscoIORT0;
0587 if (logicDiscoIORT0) delete logicDiscoIORT0;
0588 if (solidDiscoIORT0) delete solidDiscoIORT0;
0589
0590 ConstructDisc();
0591
0592
0593 G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0594 G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0595
0596 PrintParameters();
0597 }
0598
0599 void IORTDetectorConstruction::DeleteDisc()
0600 {
0601 if (physiDiscoIORT1) delete physiDiscoIORT1;
0602 if (logicDiscoIORT1) delete logicDiscoIORT1;
0603 if (solidDiscoIORT1) delete solidDiscoIORT1;
0604
0605 if (physiDiscoIORT) delete physiDiscoIORT;
0606 if (logicDiscoIORT) delete logicDiscoIORT;
0607 if (solidDiscoIORT) delete solidDiscoIORT;
0608
0609 if (physiDiscoIORT0) delete physiDiscoIORT0;
0610 if (logicDiscoIORT0) delete logicDiscoIORT0;
0611 if (solidDiscoIORT0) delete solidDiscoIORT0;
0612
0613 G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0614 G4RunManager::GetRunManager() -> PhysicsHasBeenModified();
0615 }
0616
0617
0618 void IORTDetectorConstruction::PrintParameters()
0619 {
0620
0621 G4cout << "The (X,Y,Z) dimensions of the phantom are : (" <<
0622 G4BestUnit( phantom -> GetXHalfLength()*2., "Length") << ',' <<
0623 G4BestUnit( phantom -> GetYHalfLength()*2., "Length") << ',' <<
0624 G4BestUnit( phantom -> GetZHalfLength()*2., "Length") << ')' << G4endl;
0625
0626 G4cout << "The (X,Y,Z) dimensions of the detector are : (" <<
0627 G4BestUnit( detector -> GetXHalfLength()*2., "Length") << ',' <<
0628 G4BestUnit( detector -> GetYHalfLength()*2., "Length") << ',' <<
0629 G4BestUnit( detector -> GetZHalfLength()*2., "Length") << ')' << G4endl;
0630
0631 G4cout << "Displacement between Phantom and World is: ";
0632 G4cout << "DX= "<< G4BestUnit(phantomPosition.getX(),"Length") <<
0633 "DY= "<< G4BestUnit(phantomPosition.getY(),"Length") <<
0634 "DZ= "<< G4BestUnit(phantomPosition.getZ(),"Length") << G4endl;
0635 }
0636