remove: user action

This commit is contained in:
liuyihui 2022-05-08 17:43:51 +08:00
parent e7026fc966
commit 06b92fd866
8 changed files with 2 additions and 98 deletions

View File

@ -13,10 +13,6 @@ public:
~DetectorConstruction() override;
G4VPhysicalVolume* Construct() override;
G4LogicalVolume* GetScoringVolume() const { return fScoringVolume; }
protected:
G4LogicalVolume* fScoringVolume = nullptr;
};
#endif

View File

@ -14,11 +14,8 @@ public:
void BeginOfEventAction(const G4Event*) override;
void EndOfEventAction(const G4Event*) override;
void AddEdep(G4double edep) { fEdep += edep; }
private:
RunAction* fRunAction = nullptr;
G4double fEdep = 0.;
};
#endif

View File

@ -14,12 +14,6 @@ public:
void BeginOfRunAction(const G4Run*) override;
void EndOfRunAction(const G4Run*) override;
void AddEdep(G4double edep);
private:
G4Accumulable<G4double> fEdep = 0.;
G4Accumulable<G4double> fEdep2 = 0.;
};
#endif

View File

@ -16,7 +16,6 @@ public:
private:
EventAction* fEventAction = nullptr;
G4LogicalVolume* fScoringVolume = nullptr;
};
#endif

View File

@ -18,7 +18,5 @@ G4VPhysicalVolume* DetectorConstruction::Construct() {
G4VPhysicalVolume* physics_world =
new G4PVPlacement(0, G4ThreeVector(0, 0, 0), logic_world, "world", 0, false, 0, true);
fScoringVolume = logic_world;
return physics_world;
}

View File

@ -8,6 +8,6 @@ EventAction::EventAction(RunAction* r) : fRunAction(r) {}
EventAction::~EventAction() {}
void EventAction::BeginOfEventAction(const G4Event* event) { fEdep = 0.; }
void EventAction::BeginOfEventAction(const G4Event* event) { }
void EventAction::EndOfEventAction(const G4Event* event) { fRunAction->AddEdep(fEdep); }
void EventAction::EndOfEventAction(const G4Event* event) { }

View File

@ -11,77 +11,12 @@
#include "PrimaryGeneratorAction.h"
RunAction::RunAction() {
const G4double milligray = 1.e-3 * gray;
const G4double microgray = 1.e-6 * gray;
const G4double nanogray = 1.e-9 * gray;
const G4double picogray = 1.e-12 * gray;
new G4UnitDefinition("milligray", "mGy", "Dose", milligray);
new G4UnitDefinition("microgray", "uGy", "Dose", microgray);
new G4UnitDefinition("nanogray", "nGy", "Dose", nanogray);
new G4UnitDefinition("picogray", "pGy", "Dose", picogray);
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->RegisterAccumulable(fEdep);
accumulableManager->RegisterAccumulable(fEdep2);
}
RunAction::~RunAction() {}
void RunAction::BeginOfRunAction(const G4Run*) {
G4RunManager::GetRunManager()->SetRandomNumberStore(false);
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->Reset();
}
void RunAction::EndOfRunAction(const G4Run* run) {
G4int nofEvents = run->GetNumberOfEvent();
if (nofEvents == 0) return;
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->Merge();
G4double edep = fEdep.GetValue();
G4double edep2 = fEdep2.GetValue();
G4double rms = edep2 - edep * edep / nofEvents;
if (rms > 0.)
rms = std::sqrt(rms);
else
rms = 0.;
const DetectorConstruction* detConstruction =
static_cast<const DetectorConstruction*>(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
G4double mass = detConstruction->GetScoringVolume()->GetMass();
G4double dose = edep / mass;
G4double rmsDose = rms / mass;
G4String runCondition;
const PrimaryGeneratorAction* generatorAction =
static_cast<const PrimaryGeneratorAction*>(G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
if (generatorAction) {
const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
runCondition += particleGun->GetParticleDefinition()->GetParticleName();
runCondition += " of ";
G4double particleEnergy = particleGun->GetParticleEnergy();
runCondition += G4BestUnit(particleEnergy, "Energy");
}
// Print
if (IsMaster()) {
G4cout << G4endl << "--------------------End of Global Run-----------------------";
} else {
G4cout << G4endl << "--------------------End of Local Run------------------------";
}
G4cout << G4endl << " The run consists of " << nofEvents << " " << runCondition << G4endl
<< " Cumulated dose per run, in scoring volume : " << G4BestUnit(dose, "Dose")
<< " rms = " << G4BestUnit(rmsDose, "Dose") << G4endl
<< "------------------------------------------------------------" << G4endl << G4endl;
}
void RunAction::AddEdep(G4double edep) {
// 累加沉积能量
fEdep += edep;
fEdep2 += edep * edep;
}

View File

@ -12,19 +12,4 @@ SteppingAction::SteppingAction(EventAction* e) : fEventAction(e) {}
SteppingAction::~SteppingAction() {}
void SteppingAction::UserSteppingAction(const G4Step* step) {
if (!fScoringVolume) {
const DetectorConstruction* detConstruction =
static_cast<const DetectorConstruction*>(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
fScoringVolume = detConstruction->GetScoringVolume();
}
// 获取当前的 Volume
G4LogicalVolume* volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
// 检查是否在计算的 Volume Shape 2
if (volume != fScoringVolume) return;
// 获取当前 step 的沉积能量
G4double edepStep = step->GetTotalEnergyDeposit();
fEventAction->AddEdep(edepStep);
}