|
|
Line 71: |
Line 71: |
| | | |
| | | |
- | <u> Simple example of <span style="color:#ff0000"> MyDetectorConstruction </span> </u>: | + | <u> Simple example of class <span style="color:#ff0000"> MyDetectorConstruction </span> </u>: |
| | | |
| + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | class MyDetectorConstruction:public G4VUserDetectorConstruction { |
| | | |
- | <span style="color:#800000"> class MyDetectorConstruction:public G4VUserDetectorConstruction { </span>
| + | public: |
- | | + | |
- | <span style="color:#800000"> public: </span>
| + | |
| | | |
- | <span style="color:#800000"> MyDetectorConstruction(); </span>
| + | MyDetectorConstruction(); |
| | | |
- | <span style="color:#800000"> ~MyDetectorConstruction(); </span>
| + | ~MyDetectorConstruction(); |
| | | |
- | <span style="color:#800000"> virtual G4VPhysicalVolume* Construct(); </span>
| + | virtual G4VPhysicalVolume* Construct(); |
| | | |
| | | |
- | <span style="color:#800000"> private: </span>
| + | private: |
| | | |
- | <span style="color:#800000"> void DefineMaterials(); }; </span>
| + | void DefineMaterials(); }; |
- | | + | </pre> |
| | | |
| Now construct the detector. Your detector is always placed in a mother volume called the world volume. | | Now construct the detector. Your detector is always placed in a mother volume called the world volume. |
| | | |
| | | |
- | <span style="color:#800000"> G4PhysicalVolume* MyDetectorConstruction::Construct() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | G4PhysicalVolume* MyDetectorConstruction::Construct() { |
| | | |
- | <span style="color:#800000"> ... </span>
| + | ... |
| | | |
- | <span style="color:#800000"> // World volume </span>
| + | // World volume |
| | | |
- | <span style="color:#800000"> G4VSolid* pWorld = new G4Box("World",5*m,5*m,5*m); </span>
| + | G4VSolid* pWorld = new G4Box("World",5*m,5*m,5*m); |
| | | |
- | <span style="color:#800000"> G4LogicalVolume* pWorldLog = new G4LogicalVolume(pWorld,vacuum, "World"); </span>
| + | G4LogicalVolume* pWorldLog = new G4LogicalVolume(pWorld,vacuum, "World"); |
| | | |
- | <span style="color:#800000"> G4VPhysicalVolume* pWorldPhys = new G4PVPlacement(0,G4ThreeVector(),pWorldLog,"World",0,false,0); </span>
| + | G4VPhysicalVolume* pWorldPhys = new G4PVPlacement(0,G4ThreeVector(),pWorldLog,"World",0,false,0); |
| + | </pre> |
| | | |
| | | |
- | <span style="color:#800000"> // Water box </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | // Water box </span> |
| | | |
- | <span style="color:#800000"> G4VSolid* pBoxSolid = new G4Box(“WaterBox”, 1.*m, 2.*m, 3.*m); </span>
| + | G4VSolid* pBoxSolid = new G4Box(“WaterBox”, 1.*m, 2.*m, 3.*m); |
| | | |
- | <span style="color:#800000"> G4LogicalVolume* pBoxLog = new G4LogicalVolume( pBoxSolid, water, “WaterBox”); </span>
| + | G4LogicalVolume* pBoxLog = new G4LogicalVolume( pBoxSolid, water, “WaterBox”); |
| | | |
- | <span style="color:#800000"> G4VPhysicalVolume* aBoxPhys = new G4PVPlacement( pRotation, G4ThreeVector(posX, posY, posZ), pBoxLog, “WaterBox”, pWorldLog, false, copyNo); ... } </span>
| + | G4VPhysicalVolume* aBoxPhys = new G4PVPlacement( pRotation, G4ThreeVector(posX, posY, posZ), pBoxLog, “WaterBox”, pWorldLog, false, copyNo); ... } |
| + | </pre> |
| | | |
| | | |
Line 118: |
Line 122: |
| | | |
| | | |
- | <span style="color:#800000"> void MyDetectorConstruction::DefineMaterials() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyDetectorConstruction::DefineMaterials() { |
| | | |
- | <span style="color:#800000"> ... </span>
| + | ... |
| | | |
- | <span style="color:#800000"> G4Element* H = new G4Element("Hydrogen","H",z=1.,a= 1.01*g/mole); </span>
| + | G4Element* H = new G4Element("Hydrogen","H",z=1.,a= 1.01*g/mole); |
| | | |
- | <span style="color:#800000"> G4Element* O = new G4Element("Oxygen","O",z=8.,a=16.00*g/mole); </span>
| + | G4Element* O = new G4Element("Oxygen","O",z=8.,a=16.00*g/mole); |
| | | |
| | | |
- | <span style="color:#800000"> density = 1.000*g/cm3; </span>
| + | density = 1.000*g/cm3; |
| | | |
- | <span style="color:#800000"> G4Material* water = new G4Material("Water",density,ncomp=2); </span>
| + | G4Material* water = new G4Material("Water",density,ncomp=2); |
| | | |
- | <span style="color:#800000"> water->AddElement(H, natoms=2); </span>
| + | water->AddElement(H, natoms=2); |
| | | |
- | <span style="color:#800000"> water->AddElement(O, natoms=1); ...} </span>
| + | water->AddElement(O, natoms=1); ...} |
| + | </pre> |
| | | |
| | | |
Line 155: |
Line 161: |
| | | |
| | | |
- | <u> Simple example of <span style="color:#ff0000"> MyPhysicsList </span> </u>: | + | <u> Simple example of class <span style="color:#ff0000"> MyPhysicsList </span> </u>: |
| | | |
| | | |
- | <span style="color:#800000"> class MyPhysicsList:public G4VUserPhysicsList() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | class MyPhysicsList:public G4VUserPhysicsList() { |
| | | |
- | <span style="color:#800000"> public: </span>
| + | public: |
| | | |
- | <span style="color:#800000"> MyPhysicsList(); </span>
| + | MyPhysicsList(); |
| | | |
- | <span style="color:#800000"> ~MyPhysicsList(); </span>
| + | ~MyPhysicsList(); |
| | | |
- | <span style="color:#800000"> void ConstructParticle(); </span>
| + | void ConstructParticle(); |
| | | |
- | <span style="color:#800000"> void ConstructProcess(); </span>
| + | void ConstructProcess(); |
| | | |
- | <span style="color:#800000"> void SetCuts(); } </span>
| + | void SetCuts(); } |
| + | </pre> |
| | | |
| | | |
Line 176: |
Line 184: |
| | | |
| | | |
- | <span style="color:#800000"> void MyPhysicsList::ConstructParticle() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyPhysicsList::ConstructParticle() { |
| | | |
- | <span style="color:#800000"> // Define the particles </span>
| + | // Define the particles |
| | | |
- | <span style="color:#800000"> G4Electron::ElectronDefinition(); </span>
| + | G4Electron::ElectronDefinition(); |
| | | |
- | <span style="color:#800000"> G4Positron::PositronDefinition(); </span>
| + | G4Positron::PositronDefinition(); |
| | | |
- | <span style="color:#800000"> G4Proton::ProtonDefinition(); </span>
| + | G4Proton::ProtonDefinition(); |
| | | |
- | <span style="color:#800000"> G4Neutron::NeutronDefinition(); </span>
| + | G4Neutron::NeutronDefinition(); |
| | | |
- | <span style="color:#800000"> G4Gamma::GammaDefinition(); ... } </span>
| + | G4Gamma::GammaDefinition(); ... } |
| + | </pre> |
| | | |
| | | |
Line 208: |
Line 218: |
| | | |
| | | |
- | <span style="color:#800000"> void MyPhysicsList::ConstructProcess() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyPhysicsList::ConstructProcess() { |
| | | |
- | <span style="color:#800000"> AddTransportation(); // Assign transportation process to all particles </span>
| + | AddTransportation(); // Assign transportation process to all particles |
| | | |
- | <span style="color:#800000"> ConstructEM(); // Electromagnetic processes </span>
| + | ConstructEM(); // Electromagnetic processes |
| | | |
- | <span style="color:#800000"> ConstructGeneral(); // Other processes } </span>
| + | ConstructGeneral(); // Other processes } |
| + | </pre> |
| | | |
| | | |
Line 220: |
Line 232: |
| | | |
| | | |
- | <span style="color:#800000"> void MyPhysicsList::ConstructEM() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyPhysicsList::ConstructEM() { |
| | | |
- | <span style="color:#800000"> aParticleIterator->reset(); </span>
| + | aParticleIterator->reset(); |
| | | |
- | <span style="color:#800000"> while((*aParticleIterator)()){ </span>
| + | while((*aParticleIterator)()){ |
| | | |
- | <span style="color:#800000"> G4ParticleDefinition* particle = aParticleIterator->value(); </span>
| + | G4ParticleDefinition* particle = aParticleIterator->value(); |
| | | |
- | <span style="color:#800000"> G4ProcessManager* pmanager = particle->GetProcessManager(); </span>
| + | G4ProcessManager* pmanager = particle->GetProcessManager(); |
| | | |
- | <span style="color:#800000"> G4String particleName = particle->GetParticleName(); </span>
| + | G4String particleName = particle->GetParticleName(); |
| | | |
- | <span style="color:#800000"> if (particleName == "gamma") { </span>
| + | if (particleName == "gamma") { |
| | | |
- | <span style="color:#800000"> pmanager->AddDiscreteProcess(new G4GammaConversion); ...} </span>
| + | pmanager->AddDiscreteProcess(new G4GammaConversion); ...} |
- |
| + | </pre> |
| + | |
| | | |
- | <span style="color:#800000"> void MyPhysicsList::ConstructGeneral() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyPhysicsList::ConstructGeneral() { |
| | | |
- | <span style="color:#800000"> G4Decay* theDecayProcess = new G4Decay() </span>
| + | G4Decay* theDecayProcess = new G4Decay() |
| | | |
- | <span style="color:#800000"> aParticleIterator->reset(); </span>
| + | aParticleIterator->reset(); |
| | | |
- | <span style="color:#800000"> while((*aParticleIterator)()) { </span>
| + | while((*aParticleIterator)()) { |
| | | |
- | <span style="color:#800000"> G4ParticleDefinition* particle = aParticleIterator->value(); </span>
| + | G4ParticleDefinition* particle = aParticleIterator->value(); |
| | | |
- | <span style="color:#800000"> G4ProcessManager* pmanager = particle->GetProcessManager(); </span>
| + | G4ProcessManager* pmanager = particle->GetProcessManager(); |
| | | |
- | <span style="color:#800000"> if theDecayProcess->IsApplicable(*particle)) { </span>
| + | if theDecayProcess->IsApplicable(*particle)) { |
| | | |
- | <span style="color:#800000"> pmanager->AddProcess(theDecayProcess); </span>
| + | pmanager->AddProcess(theDecayProcess); |
| | | |
- | <span style="color:#800000"> pmanager->SetProcessOrdering(theDecayProcess,idxPostStep); </span>
| + | pmanager->SetProcessOrdering(theDecayProcess,idxPostStep); |
| | | |
- | <span style="color:#800000"> pmanager->SetProcessOrdering(theDecayProcess,idxAtRest); }}} </span>
| + | pmanager->SetProcessOrdering(theDecayProcess,idxAtRest); }}} |
| + | </pre> |
| | | |
| | | |
Line 261: |
Line 277: |
| | | |
| | | |
- | <span style="color:#800000"> void MyPhysicsList::SetCuts() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyPhysicsList::SetCuts() { </span> |
| | | |
- | <span style="color:#800000"> defaultCutValue = 1.0*mm; </span>
| + | defaultCutValue = 1.0*mm; |
| | | |
- | <span style="color:#800000"> SetCutValue(defaultCutValue, "gamma"); </span>
| + | SetCutValue(defaultCutValue, "gamma"); |
| | | |
- | <span style="color:#800000"> SetCutValue(defaultCutValue, "e+"); </span>
| + | SetCutValue(defaultCutValue, "e+"); |
| | | |
- | <span style="color:#800000"> SetCutValue(defaultCutValue, "e-"); </span>
| + | SetCutValue(defaultCutValue, "e-"); |
| + | </pre> |
| | | |
| | | |
Line 278: |
Line 296: |
| | | |
| | | |
- | <u> Simple example of <span style="color:#ff0000"> MyPhysicsList </span> </u>: | + | <u> Simple example of class <span style="color:#ff0000"> MyPhysicsList </span> </u>: |
| | | |
| | | |
- | <span style="color:#800000"> class MyPhysicsList:public G4VModularPhysicsList { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | class MyPhysicsList:public G4VModularPhysicsList { |
| | | |
- | <span style="color:#800000"> public: </span>
| + | public: |
| | | |
- | <span style="color:#800000"> MyPhysicsList(); </span>
| + | MyPhysicsList(); |
| | | |
- | <span style="color:#800000"> ~MyPhysicsList(); </span>
| + | ~MyPhysicsList(); |
| | | |
- | <span style="color:#800000"> virtual void ConstructParticle(); </span>
| + | virtual void ConstructParticle(); |
| | | |
- | <span style="color:#800000"> virtual void SetCuts(); </span>
| + | virtual void SetCuts(); |
| | | |
- | <span style="color:#800000"> void AddPhysicsList(const G4String& name); </span>
| + | void AddPhysicsList(const G4String& name); |
| | | |
- | <span style="color:#800000"> virtual void ConstructProcess(); </span>
| + | virtual void ConstructProcess(); |
| | | |
| | | |
- | <span style="color:#800000"> private: </span>
| + | private: |
| | | |
- | <span style="color:#800000"> G4String fEmName; </span>
| + | G4String fEmName; |
| | | |
- | <span style="color:#800000"> G4VPhysicsConstructor* fEmPhysicsList; </span>
| + | G4VPhysicsConstructor* fEmPhysicsList; |
| | | |
- | <span style="color:#800000"> G4VPhysicsConstructor* fDecPhysicsList; </span>
| + | G4VPhysicsConstructor* fDecPhysicsList; |
| | | |
- | <span style="color:#800000"> std::vector<G4VPhysicsConstructor*> fHadronPhysicsList; }; </span>
| + | std::vector<G4VPhysicsConstructor*> fHadronPhysicsList; }; |
| + | </pre> |
| | | |
| | | |
Line 312: |
Line 332: |
| | | |
| | | |
- | <span style="color:#800000"> void MyPhysicsList::AddPhysicsList(const G4String& name) { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyPhysicsList::AddPhysicsList(const G4String& name) { |
| | | |
- | <span style="color:#800000"> ... </span>
| + | ... |
| | | |
- | <span style="color:#800000"> if (name == "emstandard_opt3") { </span>
| + | if (name == "emstandard_opt3") { |
| | | |
- | <span style="color:#800000"> fEmName = name; </span>
| + | fEmName = name; |
| | | |
- | <span style="color:#800000"> delete fEmPhysicsList; </span>
| + | delete fEmPhysicsList; |
| | | |
- | <span style="color:#800000"> fEmPhysicsList = new G4EmStandardPhysics_option3(); </span>
| + | fEmPhysicsList = new G4EmStandardPhysics_option3(); |
| | | |
| | | |
- | <span style="color:#800000"> } else if (name == "emlivermore") { </span>
| + | } else if (name == "emlivermore") { |
| | | |
- | <span style="color:#800000"> fEmName = name; </span>
| + | fEmName = name; |
| | | |
- | <span style="color:#800000"> delete fEmPhysicsList; </span>
| + | delete fEmPhysicsList; |
| | | |
- | <span style="color:#800000"> fEmPhysicsList = new G4EmLivermorePhysics(); </span>
| + | fEmPhysicsList = new G4EmLivermorePhysics(); |
| | | |
| | | |
- | <span style="color:#800000"> } else if (name == "empenelope") { </span>
| + | } else if (name == "empenelope") { |
| | | |
- | <span style="color:#800000"> fEmName = name; </span>
| + | fEmName = name; |
| | | |
- | <span style="color:#800000"> delete fEmPhysicsList; </span>
| + | delete fEmPhysicsList; |
| | | |
- | <span style="color:#800000"> fEmPhysicsList = new G4EmPenelopePhysics(); </span>
| + | fEmPhysicsList = new G4EmPenelopePhysics(); |
| | | |
| | | |
- | <span style="color:#800000"> } else if (name == "HElastic") { </span>
| + | } else if (name == "HElastic") { |
| | | |
- | <span style="color:#800000"> fHadronPhysicsList.push_back( new G4HadronHElasticPhysics()); </span>
| + | fHadronPhysicsList.push_back( new G4HadronHElasticPhysics()); |
| | | |
| | | |
- | <span style="color:#800000"> } else if (name == "HInelastic") { </span>
| + | } else if (name == "HInelastic") { |
| | | |
- | <span style="color:#800000"> fHadronPhysicsList.push_back(new G4HadronInelasticQBBC()); </span>
| + | fHadronPhysicsList.push_back(new G4HadronInelasticQBBC()); |
| | | |
- | <span style="color:#800000"> } ... } </span>
| + | } ... } |
| + | </pre> |
| | | |
| | | |
Line 358: |
Line 380: |
| | | |
| | | |
- | <span style="color:#800000"> void MyPhysicsList::ConstructProcess() { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | void MyPhysicsList::ConstructProcess() { |
| | | |
- | <span style="color:#800000"> AddTransportation(); // transportation </span>
| + | AddTransportation(); // transportation |
| | | |
- | <span style="color:#800000"> fEmPhysicsList->ConstructProcess(); // electromagnetic physics list </span>
| + | fEmPhysicsList->ConstructProcess(); // electromagnetic physics list |
| | | |
- | <span style="color:#800000"> fDecPhysicsList->ConstructProcess(); // decay physics list </span>
| + | fDecPhysicsList->ConstructProcess(); // decay physics list |
| | | |
- | <span style="color:#800000"> for(size_t i=0; i<fHadronPhys.size(); i++) { // hadronic physics lists </span>
| + | for(size_t i=0; i<fHadronPhys.size(); i++) { // hadronic physics lists |
| | | |
- | <span style="color:#800000"> fHadronPhys[i]->ConstructProcess(); } } </span>
| + | fHadronPhys[i]->ConstructProcess(); } } |
| + | </pre> |
| | | |
| | | |
Line 383: |
Line 407: |
| | | |
| | | |
- | <span style="color:#800000"> G4PhysListFactory factory* physListFactory = new G4PhysListFactory(); </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | G4PhysListFactory factory* physListFactory = new G4PhysListFactory(); |
| | | |
- | <span style="color:#800000"> G4VUserPhysicsList* physicsList = physListFactory->GetReferencePhysList(“FTFP_BERT”); </span>
| + | G4VUserPhysicsList* physicsList = physListFactory->GetReferencePhysList(“FTFP_BERT”); |
| | | |
- | <span style="color:#800000"> runManager->SetUserInitialization(physicsList); </span>
| + | runManager->SetUserInitialization(physicsList); |
| + | </pre> |
| | | |
| | | |
Line 406: |
Line 432: |
| | | |
| | | |
- | <u> Simple example of <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using particle gun </u>: | + | <u> Simple example of class <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using particle gun </u>: |
| | | |
| | | |
- | <span style="color:#800000"> class MyPrimaryGeneratorAction:public G4VUserPrimaryGeneratorAction { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | class MyPrimaryGeneratorAction:public G4VUserPrimaryGeneratorAction { |
| | | |
- | <span style="color:#800000"> public: </span>
| + | public: |
| | | |
- | <span style="color:#800000"> MyPrimaryGeneratorAction( </span>
| + | MyPrimaryGeneratorAction( |
| | | |
- | <span style="color:#800000"> const G4String& particleName = "proton", </span>
| + | const G4String& particleName = "proton", |
| | | |
- | <span style="color:#800000"> G4double energy = 1.*CLHEP::MeV, </span>
| + | G4double energy = 1.*CLHEP::MeV, |
| | | |
- | <span style="color:#800000"> G4ThreeVector position= G4ThreeVector(0,0,0), </span>
| + | G4ThreeVector position= G4ThreeVector(0,0,0), |
| | | |
- | <span style="color:#800000"> G4ThreeVector momentumDirection = G4ThreeVector(0,0,1)); </span>
| + | G4ThreeVector momentumDirection = G4ThreeVector(0,0,1)); |
| | | |
- | <span style="color:#800000"> ~MyPrimaryGeneratorAction(); </span>
| + | ~MyPrimaryGeneratorAction(); |
| | | |
- | <span style="color:#800000"> virtual void GeneratePrimaries(G4Event*); </span>
| + | virtual void GeneratePrimaries(G4Event*); |
| | | |
| | | |
- | <span style="color:#800000"> private: </span>
| + | private: |
| | | |
- | <span style="color:#800000"> G4ParticleGun* fParticleGun; }; </span>
| + | G4ParticleGun* fParticleGun; }; |
| + | </pre> |
| | | |
| | | |
- | <u> Simple example of <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using general particle source </u>: | + | <u> Simple example of class <span style="color:#ff0000"> MyPrimaryGeneratorAction </span> using general particle source </u>: |
| | | |
| | | |
- | <span style="color:#800000"> class MyPrimaryGeneratorAction:public G4VUserPrimaryGeneratorAction { </span> | + | <pre style="color: #800000; background-color: #dcdcdc"> |
| + | class MyPrimaryGeneratorAction:public G4VUserPrimaryGeneratorAction { |
| | | |
- | <span style="color:#800000"> public: </span>
| + | public: |
| | | |
- | <span style="color:#800000"> MyPrimaryGeneratorAction(); </span>
| + | MyPrimaryGeneratorAction(); |
| | | |
- | <span style="color:#800000"> ~MyPrimaryGeneratorAction(); </span>
| + | ~MyPrimaryGeneratorAction(); |
| | | |
- | <span style="color:#800000"> virtual void GeneratePrimaries(G4Event*); </span>
| + | virtual void GeneratePrimaries(G4Event*); |
| | | |
| | | |
- | <span style="color:#800000"> private: </span>
| + | private: |
| | | |
- | <span style="color:#800000"> static const G4String ParticleName; </span>
| + | static const G4String ParticleName; |
| | | |
- | <span style="color:#800000"> static const G4double ParticleEnergy; </span>
| + | static const G4double ParticleEnergy; |
| | | |
- | <span style="color:#800000"> G4GeneralParticleSource* fGeneralParticleSource; }; </span>
| + | G4GeneralParticleSource* fGeneralParticleSource; }; |
| + | </pre> |
| | | |
| | | |