| 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: Tst1DetectorConstruction.cc,v 1.2 2007/08/30 05:13:34 asaim Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 |
|
|---|
| 32 | #include "Tst1DetectorConstruction.hh"
|
|---|
| 33 |
|
|---|
| 34 | #include "G4Material.hh"
|
|---|
| 35 | #include "G4Box.hh"
|
|---|
| 36 | #include "G4LogicalVolume.hh"
|
|---|
| 37 | #include "G4PVPlacement.hh"
|
|---|
| 38 |
|
|---|
| 39 | #include "G4VisAttributes.hh"
|
|---|
| 40 | #include "G4Colour.hh"
|
|---|
| 41 |
|
|---|
| 42 | #include "G4SDManager.hh"
|
|---|
| 43 | #include "G4MultiFunctionalDetector.hh"
|
|---|
| 44 | #include "G4VPrimitiveScorer.hh"
|
|---|
| 45 | #include "G4PSEnergyDeposit.hh"
|
|---|
| 46 | #include "G4PSTrackLength.hh"
|
|---|
| 47 | #include "G4PSNofStep.hh"
|
|---|
| 48 | #include "G4SDParticleFilter.hh"
|
|---|
| 49 |
|
|---|
| 50 | #include "G4ios.hh"
|
|---|
| 51 |
|
|---|
| 52 | Tst1DetectorConstruction::Tst1DetectorConstruction()
|
|---|
| 53 | :constructed(false)
|
|---|
| 54 | {;}
|
|---|
| 55 |
|
|---|
| 56 | Tst1DetectorConstruction::~Tst1DetectorConstruction()
|
|---|
| 57 | {;}
|
|---|
| 58 |
|
|---|
| 59 | G4VPhysicalVolume* Tst1DetectorConstruction::Construct()
|
|---|
| 60 | {
|
|---|
| 61 | if(!constructed)
|
|---|
| 62 | {
|
|---|
| 63 | constructed = true;
|
|---|
| 64 | DefineMaterials();
|
|---|
| 65 | SetupGeometry();
|
|---|
| 66 | SetupDetectors();
|
|---|
| 67 | }
|
|---|
| 68 | return worldPhys;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | void Tst1DetectorConstruction::DefineMaterials()
|
|---|
| 72 | {
|
|---|
| 73 | G4String name, symbol; //a=mass of a mole;
|
|---|
| 74 | G4double a, z, density; //z=mean number of protons;
|
|---|
| 75 |
|
|---|
| 76 | G4int ncomponents, natoms;
|
|---|
| 77 | G4double fractionmass;
|
|---|
| 78 |
|
|---|
| 79 | //
|
|---|
| 80 | // define Elements
|
|---|
| 81 | //
|
|---|
| 82 |
|
|---|
| 83 | a = 1.01*g/mole;
|
|---|
| 84 | G4Element* H = new G4Element(name="Hydrogen",symbol="H" , z= 1., a);
|
|---|
| 85 |
|
|---|
| 86 | a = 14.01*g/mole;
|
|---|
| 87 | G4Element* N = new G4Element(name="Nitrogen",symbol="N" , z= 7., a);
|
|---|
| 88 |
|
|---|
| 89 | a = 16.00*g/mole;
|
|---|
| 90 | G4Element* O = new G4Element(name="Oxygen" ,symbol="O" , z= 8., a);
|
|---|
| 91 |
|
|---|
| 92 | //
|
|---|
| 93 | // define a material from elements. case 1: chemical molecule
|
|---|
| 94 | //
|
|---|
| 95 |
|
|---|
| 96 | density = 1.000*g/cm3;
|
|---|
| 97 | water = new G4Material(name="Water", density, ncomponents=2);
|
|---|
| 98 | water->AddElement(H, natoms=2);
|
|---|
| 99 | water->AddElement(O, natoms=1);
|
|---|
| 100 |
|
|---|
| 101 | //
|
|---|
| 102 | // define a material from elements. case 2: mixture by fractional mass
|
|---|
| 103 | //
|
|---|
| 104 |
|
|---|
| 105 | density = 1.290*mg/cm3;
|
|---|
| 106 | air = new G4Material(name="Air" , density, ncomponents=2);
|
|---|
| 107 | air->AddElement(N, fractionmass=0.7);
|
|---|
| 108 | air->AddElement(O, fractionmass=0.3);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | void Tst1DetectorConstruction::SetupGeometry()
|
|---|
| 112 | {
|
|---|
| 113 | //
|
|---|
| 114 | // World
|
|---|
| 115 | //
|
|---|
| 116 | G4VSolid* worldSolid = new G4Box("World",2.*m,2.*m,2.*m);
|
|---|
| 117 | G4LogicalVolume* worldLogical = new G4LogicalVolume(worldSolid,air,"World");
|
|---|
| 118 | worldPhys = new G4PVPlacement(0,G4ThreeVector(),worldLogical,"World",
|
|---|
| 119 | 0,false,0);
|
|---|
| 120 |
|
|---|
| 121 | //
|
|---|
| 122 | // Phantom
|
|---|
| 123 | //
|
|---|
| 124 | G4VSolid* phantomSolid = new G4Box("Calor",1.*m,1.*m,1.*m);
|
|---|
| 125 | G4LogicalVolume* phantomLogical = new G4LogicalVolume(phantomSolid,water,"Phantom");
|
|---|
| 126 | phantomPhys = new G4PVPlacement(0,G4ThreeVector(),phantomLogical,"Phantom",
|
|---|
| 127 | worldLogical,false,0);
|
|---|
| 128 | //
|
|---|
| 129 | // Visualization attributes
|
|---|
| 130 | //
|
|---|
| 131 | // worldLogical->SetVisAttributes(G4VisAttributes::Invisible);
|
|---|
| 132 | G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
|
|---|
| 133 | simpleBoxVisAtt->SetVisibility(true);
|
|---|
| 134 | phantomLogical->SetVisAttributes(simpleBoxVisAtt);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | void Tst1DetectorConstruction::SetupDetectors()
|
|---|
| 138 | {
|
|---|
| 139 | G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
|
|---|
| 140 | G4LogicalVolume* phantomLogical = phantomPhys->GetLogicalVolume();
|
|---|
| 141 |
|
|---|
| 142 | G4String filterName, particleName;
|
|---|
| 143 | G4SDParticleFilter* gammaFilter = new G4SDParticleFilter(filterName="gammaFilter",particleName="gamma");
|
|---|
| 144 | G4SDParticleFilter* electronFilter = new G4SDParticleFilter(filterName="electronFilter",particleName="e-");
|
|---|
| 145 | G4SDParticleFilter* positronFilter = new G4SDParticleFilter(filterName="positronFilter",particleName="e+");
|
|---|
| 146 |
|
|---|
| 147 | G4MultiFunctionalDetector* det = new G4MultiFunctionalDetector("MassWorld");
|
|---|
| 148 |
|
|---|
| 149 | G4VPrimitiveScorer* primitive;
|
|---|
| 150 | primitive = new G4PSEnergyDeposit("eDep");
|
|---|
| 151 | det->RegisterPrimitive(primitive);
|
|---|
| 152 | primitive = new G4PSTrackLength("trackLengthGamma");
|
|---|
| 153 | primitive->SetFilter(gammaFilter);
|
|---|
| 154 | det->RegisterPrimitive(primitive);
|
|---|
| 155 | primitive = new G4PSNofStep("nStepGamma");
|
|---|
| 156 | primitive->SetFilter(gammaFilter);
|
|---|
| 157 | det->RegisterPrimitive(primitive);
|
|---|
| 158 | primitive = new G4PSTrackLength("trackLengthElec");
|
|---|
| 159 | primitive->SetFilter(electronFilter);
|
|---|
| 160 | det->RegisterPrimitive(primitive);
|
|---|
| 161 | primitive = new G4PSNofStep("nStepElec");
|
|---|
| 162 | primitive->SetFilter(electronFilter);
|
|---|
| 163 | det->RegisterPrimitive(primitive);
|
|---|
| 164 | primitive = new G4PSTrackLength("trackLengthPosi");
|
|---|
| 165 | primitive->SetFilter(positronFilter);
|
|---|
| 166 | det->RegisterPrimitive(primitive);
|
|---|
| 167 | primitive = new G4PSNofStep("nStepPosi");
|
|---|
| 168 | primitive->SetFilter(positronFilter);
|
|---|
| 169 | det->RegisterPrimitive(primitive);
|
|---|
| 170 |
|
|---|
| 171 | G4SDManager::GetSDMpointer()->AddNewDetector(det);
|
|---|
| 172 | phantomLogical->SetSensitiveDetector(det);
|
|---|
| 173 | G4SDManager::GetSDMpointer()->SetVerboseLevel(0);
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|