[807] | 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 | // |
---|
| 27 | // $Id: RE02DetectorConstruction.cc,v 1.3 2006/11/18 01:37:23 asaim Exp $ |
---|
[1230] | 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
[807] | 29 | // |
---|
| 30 | |
---|
| 31 | #include "RE02DetectorConstruction.hh" |
---|
| 32 | |
---|
| 33 | #include "G4MultiFunctionalDetector.hh" |
---|
| 34 | |
---|
| 35 | #include "RE02PSEnergyDeposit.hh" |
---|
| 36 | #include "RE02PSNofStep.hh" |
---|
| 37 | #include "RE02PSCellFlux.hh" |
---|
| 38 | #include "RE02PSPassageCellFlux.hh" |
---|
| 39 | #include "RE02PSFlatSurfaceFlux.hh" |
---|
| 40 | #include "RE02PSFlatSurfaceCurrent.hh" |
---|
| 41 | |
---|
| 42 | #include "G4SDParticleWithEnergyFilter.hh" |
---|
| 43 | #include "G4SDParticleFilter.hh" |
---|
| 44 | #include "G4SDChargedFilter.hh" |
---|
| 45 | |
---|
| 46 | #include "G4NistManager.hh" |
---|
| 47 | #include "G4Material.hh" |
---|
| 48 | #include "G4Box.hh" |
---|
| 49 | #include "G4LogicalVolume.hh" |
---|
| 50 | #include "G4PVPlacement.hh" |
---|
| 51 | #include "G4SDManager.hh" |
---|
| 52 | |
---|
| 53 | #include "G4PVParameterised.hh" |
---|
| 54 | #include "RE02NestedPhantomParameterisation.hh" |
---|
| 55 | |
---|
| 56 | #include "G4VisAttributes.hh" |
---|
| 57 | #include "G4Colour.hh" |
---|
| 58 | |
---|
| 59 | #include "G4ios.hh" |
---|
| 60 | |
---|
| 61 | //======================================================================= |
---|
| 62 | // RE02DetectorConstruction |
---|
| 63 | // |
---|
| 64 | // (Description) |
---|
| 65 | // |
---|
| 66 | // Detector construction for example RE02. |
---|
| 67 | // |
---|
| 68 | // [Geometry] |
---|
| 69 | // The world volume is defined as 200 cm x 200 cm x 200 cm box with Air. |
---|
| 70 | // Water phantom is defined as 200 mm x 200 mm x 400 mm box with Water. |
---|
| 71 | // The water phantom is divided into 100 segments in x,y plane using replication, |
---|
| 72 | // and then divided into 200 segments perpendicular to z axis using nested |
---|
| 73 | // parameterised volume. |
---|
| 74 | // These values are defined at constructor, |
---|
| 75 | // e.g. the size of water phantom (fphantomSize), and number of segmentation |
---|
| 76 | // of water phantom (fNx, fNy, fNz). |
---|
| 77 | // |
---|
| 78 | // By default, lead plates are inserted into the position of even order segments. |
---|
| 79 | // NIST database is used for materials. |
---|
| 80 | // |
---|
| 81 | // |
---|
| 82 | // [Scorer] |
---|
| 83 | // Assignment of G4MultiFunctionalDetector and G4PrimitiveScorer |
---|
| 84 | // is demonstrated in this example. |
---|
| 85 | // ------------------------------------------------- |
---|
| 86 | // The collection names of defined Primitives are |
---|
| 87 | // 0 PhantomSD/totalEDep |
---|
| 88 | // 1 PhantomSD/protonEDep |
---|
| 89 | // 2 PhantomSD/protonNStep |
---|
| 90 | // 3 PhantomSD/chargedPassCellFlux |
---|
| 91 | // 4 PhantomSD/chargedCellFlux |
---|
| 92 | // 5 PhantomSD/chargedSurfFlux |
---|
| 93 | // 6 PhantomSD/gammaSurfCurr000 |
---|
| 94 | // 7 PhantomSD/gammaSurfCurr001 |
---|
| 95 | // 9 PhantomSD/gammaSurdCurr002 |
---|
| 96 | // 10 PhantomSD/gammaSurdCurr003 |
---|
| 97 | // ------------------------------------------------- |
---|
| 98 | // Please see README for detail description. |
---|
| 99 | // |
---|
| 100 | //======================================================================= |
---|
| 101 | |
---|
| 102 | // |
---|
| 103 | RE02DetectorConstruction::RE02DetectorConstruction() |
---|
| 104 | { |
---|
| 105 | // Default size of water phantom,and segmentation. |
---|
| 106 | fphantomSize.setX(200.*mm); |
---|
| 107 | fphantomSize.setY(200.*mm); |
---|
| 108 | fphantomSize.setZ(400.*mm); |
---|
| 109 | fNx = fNy = fNz = 100; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // |
---|
| 113 | RE02DetectorConstruction::~RE02DetectorConstruction() |
---|
| 114 | {;} |
---|
| 115 | |
---|
| 116 | // |
---|
| 117 | G4VPhysicalVolume* RE02DetectorConstruction::Construct() |
---|
| 118 | { |
---|
| 119 | //===================== |
---|
| 120 | // Material Definitions |
---|
| 121 | //===================== |
---|
| 122 | // |
---|
| 123 | //-------- NIST Materials ---------------------------------------------------- |
---|
| 124 | // Material Information imported from NIST database. |
---|
| 125 | // |
---|
| 126 | G4NistManager* NISTman = G4NistManager::Instance(); |
---|
| 127 | G4Material* Air = NISTman->FindOrBuildMaterial("G4_AIR"); |
---|
| 128 | G4Material* H2O = NISTman->FindOrBuildMaterial("G4_WATER"); |
---|
| 129 | G4Material* LEAD = NISTman->FindOrBuildMaterial("G4_Pb"); |
---|
| 130 | |
---|
| 131 | // |
---|
| 132 | // Print all the materials defined. |
---|
| 133 | G4cout << G4endl << "The materials defined are : " << G4endl << G4endl; |
---|
| 134 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | //============================================================================ |
---|
| 138 | // Definitions of Solids, Logical Volumes, Physical Volumes |
---|
| 139 | //============================================================================ |
---|
| 140 | |
---|
| 141 | //------------- |
---|
| 142 | // World Volume |
---|
| 143 | //------------- |
---|
| 144 | |
---|
| 145 | G4ThreeVector worldSize = G4ThreeVector(200*cm, 200*cm, 200*cm); |
---|
| 146 | |
---|
| 147 | G4Box * solidWorld |
---|
| 148 | = new G4Box("world", worldSize.x()/2., worldSize.y()/2., worldSize.z()/2.); |
---|
| 149 | G4LogicalVolume * logicWorld |
---|
| 150 | = new G4LogicalVolume(solidWorld, Air, "World", 0, 0, 0); |
---|
| 151 | |
---|
| 152 | // |
---|
| 153 | // Must place the World Physical volume unrotated at (0,0,0). |
---|
| 154 | G4VPhysicalVolume * physiWorld |
---|
| 155 | = new G4PVPlacement(0, // no rotation |
---|
| 156 | G4ThreeVector(), // at (0,0,0) |
---|
| 157 | logicWorld, // its logical volume |
---|
| 158 | "World", // its name |
---|
| 159 | 0, // its mother volume |
---|
| 160 | false, // no boolean operations |
---|
| 161 | 0); // copy number |
---|
| 162 | |
---|
| 163 | //--------------- |
---|
| 164 | // Water Phantom |
---|
| 165 | //--------------- |
---|
| 166 | |
---|
| 167 | //................................ |
---|
| 168 | // Mother Volume of Water Phantom |
---|
| 169 | //................................ |
---|
| 170 | |
---|
| 171 | //-- Default size of water phantom is defined at constructor. |
---|
| 172 | G4ThreeVector phantomSize = fphantomSize; |
---|
| 173 | |
---|
| 174 | G4Box * solidPhantom |
---|
| 175 | = new G4Box("phantom", |
---|
| 176 | phantomSize.x()/2., phantomSize.y()/2., phantomSize.z()/2.); |
---|
| 177 | G4LogicalVolume * logicPhantom |
---|
| 178 | = new G4LogicalVolume(solidPhantom, H2O, "Phantom", 0, 0, 0); |
---|
| 179 | |
---|
| 180 | G4RotationMatrix* rot=new G4RotationMatrix(); |
---|
| 181 | //rot->rotateY(30.*deg); |
---|
| 182 | G4ThreeVector positionPhantom; |
---|
| 183 | //G4VPhysicalVolume * physiPhantom = |
---|
| 184 | new G4PVPlacement(rot, // no rotation |
---|
| 185 | positionPhantom, // at (x,y,z) |
---|
| 186 | logicPhantom, // its logical volume |
---|
| 187 | "Phantom", // its name |
---|
| 188 | logicWorld, // its mother volume |
---|
| 189 | false, // no boolean operations |
---|
| 190 | 0); // copy number |
---|
| 191 | |
---|
| 192 | //.............................................. |
---|
| 193 | // Phantom segmentation using Parameterisation |
---|
| 194 | //.............................................. |
---|
| 195 | // |
---|
| 196 | G4cout << "<-- RE02DetectorConstruction::Construct-------" <<G4endl; |
---|
| 197 | G4cout << " Water Phantom Size " << fphantomSize/mm << G4endl; |
---|
| 198 | G4cout << " Segmentation ("<< fNx<<","<<fNy<<","<<fNz<<")"<<G4endl; |
---|
| 199 | G4cout << " Lead plate at even copy # (0-False,1-True): " << IsLeadSegment() <<G4endl; |
---|
| 200 | G4cout << "<---------------------------------------------"<<G4endl; |
---|
| 201 | // Number of segmentation. |
---|
| 202 | // - Default number of segmentation is defined at constructor. |
---|
| 203 | G4int nxCells = fNx; |
---|
| 204 | G4int nyCells = fNy; |
---|
| 205 | G4int nzCells = fNz; |
---|
| 206 | |
---|
| 207 | G4ThreeVector sensSize; |
---|
| 208 | sensSize.setX(phantomSize.x()/(G4double)nxCells); |
---|
| 209 | sensSize.setY(phantomSize.y()/(G4double)nyCells); |
---|
| 210 | sensSize.setZ(phantomSize.z()/(G4double)nzCells); |
---|
| 211 | // i.e Voxel size will be 2.0 x 2.0 x 2.0 mm3 cube by default. |
---|
| 212 | // |
---|
| 213 | |
---|
| 214 | // Replication of Water Phantom Volume. |
---|
| 215 | // Y Slice |
---|
| 216 | G4String yRepName("RepY"); |
---|
| 217 | G4VSolid* solYRep = |
---|
| 218 | new G4Box(yRepName,phantomSize.x()/2.,sensSize.y()/2.,phantomSize.z()/2.); |
---|
| 219 | G4LogicalVolume* logYRep = |
---|
| 220 | new G4LogicalVolume(solYRep,H2O,yRepName); |
---|
| 221 | //G4PVReplica* yReplica = |
---|
| 222 | new G4PVReplica(yRepName,logYRep,logicPhantom,kYAxis,fNy,sensSize.y()); |
---|
| 223 | // X Slice |
---|
| 224 | G4String xRepName("RepX"); |
---|
| 225 | G4VSolid* solXRep = |
---|
| 226 | new G4Box(xRepName,sensSize.x()/2.,sensSize.y()/2.,phantomSize.z()/2.); |
---|
| 227 | G4LogicalVolume* logXRep = |
---|
| 228 | new G4LogicalVolume(solXRep,H2O,xRepName); |
---|
| 229 | //G4PVReplica* xReplica = |
---|
| 230 | new G4PVReplica(xRepName,logXRep,logYRep,kXAxis,fNx,sensSize.x()); |
---|
| 231 | // |
---|
| 232 | // |
---|
| 233 | // |
---|
| 234 | //.................................. |
---|
| 235 | // Voxel solid and logical volumes |
---|
| 236 | //.................................. |
---|
| 237 | // Z Slice |
---|
| 238 | G4String zVoxName("phantomSens"); |
---|
| 239 | G4VSolid* solVoxel = |
---|
| 240 | new G4Box(zVoxName,sensSize.x()/2.,sensSize.y()/2.,sensSize.z()/2.); |
---|
| 241 | G4LogicalVolume* logicPhantomSens = new G4LogicalVolume(solVoxel,H2O,zVoxName); |
---|
| 242 | // |
---|
| 243 | // |
---|
| 244 | std::vector<G4Material*> phantomMat(2,H2O); |
---|
| 245 | if ( IsLeadSegment() ) phantomMat[1]=LEAD; |
---|
| 246 | // |
---|
| 247 | // Parameterisation for transformation of voxels. |
---|
| 248 | // (voxel size is fixed in this example. |
---|
| 249 | // e.g. nested parameterisation handles material and transfomation of voxels.) |
---|
| 250 | RE02NestedPhantomParameterisation* paramPhantom |
---|
| 251 | = new RE02NestedPhantomParameterisation(sensSize/2.,nzCells,phantomMat); |
---|
| 252 | //G4VPhysicalVolume * physiPhantomSens = |
---|
| 253 | new G4PVParameterised("PhantomSens", // their name |
---|
| 254 | logicPhantomSens, // their logical volume |
---|
| 255 | logXRep, // Mother logical volume |
---|
| 256 | kUndefined, // Are placed along this axis |
---|
| 257 | nzCells, // Number of cells |
---|
| 258 | paramPhantom); // Parameterisation. |
---|
| 259 | // Optimization flag is avaiable for, |
---|
| 260 | // kUndefined, kXAxis, kYAxis, kZAxis. |
---|
| 261 | // |
---|
| 262 | |
---|
| 263 | //================================================ |
---|
| 264 | // Sensitive detectors : MultiFunctionalDetector |
---|
| 265 | //================================================ |
---|
| 266 | // |
---|
| 267 | // Sensitive Detector Manager. |
---|
| 268 | G4SDManager* SDman = G4SDManager::GetSDMpointer(); |
---|
| 269 | // |
---|
| 270 | // Sensitive Detector Name |
---|
| 271 | G4String phantomSDname = "PhantomSD"; |
---|
| 272 | |
---|
| 273 | //------------------------ |
---|
| 274 | // MultiFunctionalDetector |
---|
| 275 | //------------------------ |
---|
| 276 | // |
---|
| 277 | // Define MultiFunctionalDetector with name. |
---|
| 278 | G4MultiFunctionalDetector* MFDet = new G4MultiFunctionalDetector(phantomSDname); |
---|
| 279 | SDman->AddNewDetector( MFDet ); // Register SD to SDManager. |
---|
| 280 | logicPhantomSens->SetSensitiveDetector(MFDet); // Assign SD to the logical volume. |
---|
| 281 | |
---|
| 282 | //--------------------------------------- |
---|
| 283 | // SDFilter : Sensitive Detector Filters |
---|
| 284 | //--------------------------------------- |
---|
| 285 | // |
---|
| 286 | // Particle Filter for Primitive Scorer with filter name(fltName) |
---|
| 287 | // and particle name(particleName), |
---|
| 288 | // or particle names are given by add("particle name"); method. |
---|
| 289 | // |
---|
| 290 | G4String fltName,particleName; |
---|
| 291 | // |
---|
| 292 | //-- proton filter |
---|
| 293 | G4SDParticleFilter* protonFilter = |
---|
| 294 | new G4SDParticleFilter(fltName="protonFilter", particleName="proton"); |
---|
| 295 | // |
---|
| 296 | //-- electron filter |
---|
| 297 | G4SDParticleFilter* electronFilter = |
---|
| 298 | new G4SDParticleFilter(fltName="electronFilter"); |
---|
| 299 | electronFilter->add(particleName="e+"); // accept electrons. |
---|
| 300 | electronFilter->add(particleName="e-"); // accept positorons. |
---|
| 301 | // |
---|
| 302 | //-- charged particle filter |
---|
| 303 | G4SDChargedFilter* chargedFilter = |
---|
| 304 | new G4SDChargedFilter(fltName="chargedFilter"); |
---|
| 305 | |
---|
| 306 | //------------------------ |
---|
| 307 | // PS : Primitive Scorers |
---|
| 308 | //------------------------ |
---|
| 309 | // Primitive Scorers are used with SDFilters according to your purpose. |
---|
| 310 | // |
---|
| 311 | // |
---|
| 312 | //-- Primitive Scorer for Energy Deposit. |
---|
| 313 | // Total, by protons, by electrons. |
---|
| 314 | G4String psName; |
---|
| 315 | G4PSEnergyDeposit* scorer0 = new RE02PSEnergyDeposit(psName="totalEDep",fNx,fNy,fNz); |
---|
| 316 | G4PSEnergyDeposit* scorer1 = new RE02PSEnergyDeposit(psName="protonEDep",fNx,fNy,fNz); |
---|
| 317 | scorer1->SetFilter(protonFilter); |
---|
| 318 | |
---|
| 319 | // |
---|
| 320 | //-- Number of Steps for protons |
---|
| 321 | G4PSNofStep* scorer2 = new RE02PSNofStep(psName="protonNStep",fNx,fNy,fNz); |
---|
| 322 | scorer2->SetFilter(protonFilter); |
---|
| 323 | |
---|
| 324 | // |
---|
| 325 | //-- CellFlux for charged particles |
---|
| 326 | G4PSPassageCellFlux* scorer3 = new RE02PSPassageCellFlux(psName="chargedPassCellFlux", |
---|
| 327 | fNx,fNy,fNz); |
---|
| 328 | G4PSCellFlux* scorer4 = new RE02PSCellFlux(psName="chargedCellFlux", |
---|
| 329 | fNx,fNy,fNz); |
---|
| 330 | G4PSFlatSurfaceFlux* scorer5 = new RE02PSFlatSurfaceFlux(psName="chargedSurfFlux", |
---|
| 331 | fFlux_InOut,fNx,fNy,fNz); |
---|
| 332 | scorer3->SetFilter(chargedFilter); |
---|
| 333 | scorer4->SetFilter(chargedFilter); |
---|
| 334 | scorer5->SetFilter(chargedFilter); |
---|
| 335 | |
---|
| 336 | // |
---|
| 337 | //------------------------------------------------------------ |
---|
| 338 | // Register primitive scorers to MultiFunctionalDetector |
---|
| 339 | //------------------------------------------------------------ |
---|
| 340 | MFDet->RegisterPrimitive(scorer0); |
---|
| 341 | MFDet->RegisterPrimitive(scorer1); |
---|
| 342 | MFDet->RegisterPrimitive(scorer2); |
---|
| 343 | MFDet->RegisterPrimitive(scorer3); |
---|
| 344 | MFDet->RegisterPrimitive(scorer4); |
---|
| 345 | MFDet->RegisterPrimitive(scorer5); |
---|
| 346 | |
---|
| 347 | |
---|
| 348 | //======================== |
---|
| 349 | // More additional Primitive Scoreres |
---|
| 350 | //======================== |
---|
| 351 | // |
---|
| 352 | //--- Surface Current for gamma with energy bin. |
---|
| 353 | // This example creates four primitive scorers. |
---|
| 354 | // 4 bins with energy --- Primitive Scorer Name |
---|
| 355 | // 1. to 10 KeV, gammaSurfCurr000 |
---|
| 356 | // 10 keV to 100 KeV, gammaSurfCurr001 |
---|
| 357 | // 100 keV to 1 MeV, gammaSurfCurr002 |
---|
| 358 | // 1 MeV to 10 MeV. gammaSurfCurr003 |
---|
| 359 | // |
---|
| 360 | char name[16]; |
---|
| 361 | for ( G4int i = 0; i < 4; i++){ |
---|
| 362 | std::sprintf(name,"gammaSurfCurr%03d",i); |
---|
| 363 | G4String psgName(name); |
---|
| 364 | G4double kmin = std::pow(10.,(G4double)i)*keV; |
---|
| 365 | G4double kmax = std::pow(10.,(G4double)(i+1))*keV; |
---|
| 366 | //-- Particle with kinetic energy filter. |
---|
| 367 | G4SDParticleWithEnergyFilter* pkinEFilter = |
---|
| 368 | new G4SDParticleWithEnergyFilter(fltName="gammaE filter",kmin,kmax); |
---|
| 369 | pkinEFilter->add("gamma"); // Accept only gamma. |
---|
| 370 | pkinEFilter->show(); // Show accepting condition to stdout. |
---|
| 371 | //-- Surface Current Scorer which scores number of tracks in unit area. |
---|
| 372 | G4PSFlatSurfaceCurrent* scorer = |
---|
| 373 | new RE02PSFlatSurfaceCurrent(psgName,fCurrent_InOut,fNx,fNy,fNz); |
---|
| 374 | scorer->SetFilter(pkinEFilter); // Assign filter. |
---|
| 375 | MFDet->RegisterPrimitive(scorer); // Register it to MultiFunctionalDetector. |
---|
| 376 | } |
---|
| 377 | // |
---|
| 378 | |
---|
| 379 | //=============================== |
---|
| 380 | // Visualization attributes |
---|
| 381 | //=============================== |
---|
| 382 | |
---|
| 383 | G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); |
---|
| 384 | logicWorld ->SetVisAttributes(BoxVisAtt); |
---|
| 385 | //logicWorld->SetVisAttributes(G4VisAttributes::Invisible); |
---|
| 386 | |
---|
| 387 | // Mother volume of WaterPhantom |
---|
| 388 | G4VisAttributes* PhantomVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0)); |
---|
| 389 | logicPhantom->SetVisAttributes(PhantomVisAtt); |
---|
| 390 | |
---|
| 391 | // Replica |
---|
| 392 | G4VisAttributes* YRepVisAtt = new G4VisAttributes(G4Colour(0.0,1.0,0.0)); |
---|
| 393 | logYRep->SetVisAttributes(YRepVisAtt); |
---|
| 394 | G4VisAttributes* XRepVisAtt = new G4VisAttributes(G4Colour(0.0,1.0,0.0)); |
---|
| 395 | logXRep->SetVisAttributes(YRepVisAtt); |
---|
| 396 | |
---|
| 397 | // Skip the visualization for those voxels. |
---|
| 398 | logicPhantomSens->SetVisAttributes(G4VisAttributes::Invisible); |
---|
| 399 | |
---|
| 400 | |
---|
| 401 | return physiWorld; |
---|
| 402 | } |
---|
| 403 | |
---|