From c7c96ac2704c4f109e7b1fefdac1f9fe1744e621 Mon Sep 17 00:00:00 2001 From: YiHui Liu Date: Thu, 19 May 2022 15:41:19 +0800 Subject: [PATCH] change: AlAlloyS5 to Al;add: output --- G4.code-workspace | 5 ++++- include/DetectorConstruction.h | 4 ++-- include/G4HumanPhantomMessenger.h | 1 - include/PrimaryGeneratorAction.h | 7 +++---- main.cpp | 1 + src/Material.cpp | 21 +++++++++++---------- src/PrimaryGeneratorAction.cpp | 23 ++++++++++++++--------- src/RunAction.cpp | 9 ++++----- 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/G4.code-workspace b/G4.code-workspace index 5a9ad94..d0c9f72 100644 --- a/G4.code-workspace +++ b/G4.code-workspace @@ -131,7 +131,10 @@ "senum": "cpp", "value": "cpp", "ntuple": "cpp", - "free_seg": "cpp" + "free_seg": "cpp", + "base_histo": "cpp", + "c2d": "cpp", + "c3d": "cpp" } } } \ No newline at end of file diff --git a/include/DetectorConstruction.h b/include/DetectorConstruction.h index cdd3ed4..44b78b9 100644 --- a/include/DetectorConstruction.h +++ b/include/DetectorConstruction.h @@ -22,7 +22,7 @@ public: void SetPhantomModel(G4String); void SetParticleType(G4String s) { particleType = s; }; void ConstructSDandField(); - G4String GetParticleType() const { return particleType; }; + G4String GetParticleType() { return particleType; }; std::vector GetSensitiveList() const { return sensitiveList; }; private: @@ -36,7 +36,7 @@ private: private: G4String sex = "Male"; G4String model = "MIRD"; - G4String particleType = "GCR_H"; + G4String particleType = "TE"; std::vector sensitiveList; std::map sensitivities; G4HumanPhantomMaterial* material; diff --git a/include/G4HumanPhantomMessenger.h b/include/G4HumanPhantomMessenger.h index 5b2ce99..390ef34 100644 --- a/include/G4HumanPhantomMessenger.h +++ b/include/G4HumanPhantomMessenger.h @@ -2,7 +2,6 @@ #define DESCSS_HumanPhantomMessenger_h 1 class DetectorConstruction; -class PrimaryGeneratorAction; class G4UIcommand; class G4UIdirectory; diff --git a/include/PrimaryGeneratorAction.h b/include/PrimaryGeneratorAction.h index b0f48a3..797a396 100644 --- a/include/PrimaryGeneratorAction.h +++ b/include/PrimaryGeneratorAction.h @@ -14,13 +14,12 @@ public: PrimaryGeneratorAction(); ~PrimaryGeneratorAction(); - G4ParticleDefinition* DefineParticle(); virtual void GeneratePrimaries(G4Event*); - const G4ParticleGun* GetParticleGun() const { return fParticleGun; } + void DefineParticle(G4String particleType); + const G4ParticleGun* GetParticleGun() const { return fParticleGun; }; private: - G4int Z; - G4String particleType = "TE"; + G4String particleType; G4ParticleGun* fParticleGun = nullptr; }; diff --git a/main.cpp b/main.cpp index 262f28f..769b552 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,7 @@ #include "G4VisExecutive.hh" #include "QBBC.hh" + int main(int argc, char** argv) { G4UIExecutive* ui = nullptr; if (argc == 1) ui = new G4UIExecutive(argc, argv); diff --git a/src/Material.cpp b/src/Material.cpp index 5f585e7..ea581cf 100644 --- a/src/Material.cpp +++ b/src/Material.cpp @@ -24,16 +24,17 @@ void DefineMaterials() { // 5系铝合金 0.4 Si + 0.35 Fe + 0.1 Cu + 0.7 Mn + 4.5 Mg + 0.15 Cr + 0.25 Zn + 0.15 Ti + 93.4 Al density = 2.68 * g / cm3; - G4Material* AlAlloyS5 = new G4Material("AluminumAlloySeries5", density, ncomponents = 9); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Si"), fractionmass = .4 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Fe"), fractionmass = .35 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Cu"), fractionmass = .1 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Mn"), fractionmass = .7 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Mg"), fractionmass = 4.5 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Cr"), fractionmass = .15 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Zn"), fractionmass = .25 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Ti"), fractionmass = .15 * perCent); - AlAlloyS5->AddElement(nist->FindOrBuildElement("Al"), fractionmass = 93.4 * perCent); + G4Material* AlAlloyS5 = new G4Material("AluminumAlloySeries5", density, ncomponents = 1); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Si"), fractionmass = .4 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Fe"), fractionmass = .35 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Cu"), fractionmass = .1 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Mn"), fractionmass = .7 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Mg"), fractionmass = 4.5 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Cr"), fractionmass = .15 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Zn"), fractionmass = .25 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Ti"), fractionmass = .15 * perCent); + // AlAlloyS5->AddElement(nist->FindOrBuildElement("Al"), fractionmass = 93.4 * perCent); + AlAlloyS5->AddElement(nist->FindOrBuildElement("Al"), fractionmass = 100. * perCent); // 泰普龙 Taparan density = 1.44 * g / cm3; diff --git a/src/PrimaryGeneratorAction.cpp b/src/PrimaryGeneratorAction.cpp index 176bc4e..913e4d5 100644 --- a/src/PrimaryGeneratorAction.cpp +++ b/src/PrimaryGeneratorAction.cpp @@ -14,19 +14,17 @@ G4double M = 931.5; G4double C1, C2, C3, C4, sum; PrimaryGeneratorAction::PrimaryGeneratorAction() { - G4ParticleDefinition* ion = DefineParticle(); - fParticleGun = new G4ParticleGun(); - fParticleGun->SetParticleCharge(this->Z * eplus); - fParticleGun->SetParticleDefinition(ion); + DetectorConstruction* detConstruction = + (DetectorConstruction*)(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); - const DetectorConstruction* detConstruction = - static_cast(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); + fParticleGun = new G4ParticleGun(); particleType = detConstruction->GetParticleType(); + DefineParticle(particleType); } PrimaryGeneratorAction::~PrimaryGeneratorAction() { delete fParticleGun; } -G4ParticleDefinition* PrimaryGeneratorAction::DefineParticle() { +void PrimaryGeneratorAction::DefineParticle(G4String particleType) { G4double Z, A; std::string tmp, line, name; std::ifstream modelFile("assets/model.txt"); @@ -62,8 +60,8 @@ G4ParticleDefinition* PrimaryGeneratorAction::DefineParticle() { else ion = G4IonTable::GetIonTable()->GetIon(Z, A, 0.); - this->Z = Z; - return ion; + fParticleGun->SetParticleCharge(Z * eplus); + fParticleGun->SetParticleDefinition(ion); } G4double randomPhi() { @@ -162,6 +160,13 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* e) { G4ThreeVector pos = randomPos(); G4ThreeVector dir = randomDir(pos); + DetectorConstruction* detConstruction = + (DetectorConstruction*)(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); + if (particleType != detConstruction->GetParticleType()) { + particleType = detConstruction->GetParticleType(); + DefineParticle(particleType); + } + if (particleType == "TE") E = ITM(0.1, 10, pdfTElectronInv); else if (particleType == "TP") diff --git a/src/RunAction.cpp b/src/RunAction.cpp index a9b1c0b..ef02201 100644 --- a/src/RunAction.cpp +++ b/src/RunAction.cpp @@ -55,15 +55,14 @@ void RunAction::EndOfRunAction(const G4Run* run) { } if (IsMaster()) { - const DetectorConstruction* detConstruction = - static_cast(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); + DetectorConstruction* detConstruction = + (DetectorConstruction*)(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); std::ofstream edepFile("result/edep_" + detConstruction->GetParticleType() + ".txt"); for (int i = 0; i < sensitiveList.size(); i++) { G4String name = sensitiveList[i]; - edepFile << "bodyPart: " << std::setw(30) << name << " | eDep: " << std::setw(15) - << edep[name] / MeV << " MeV | eDep2: " << std::setw(15) - << edep2[name] / MeV << " MeV | rms: " << std::setw(15) + edepFile << "bodyPart: " << std::setw(30) << name << " | eDep: " << std::setw(15) << edep[name] / MeV + << " MeV | eDep2: " << std::setw(15) << edep2[name] / MeV << " MeV | rms: " << std::setw(15) << rms[name] / MeV << " MeV" << G4endl; }