マテリアル管理したい(G4NistManager)
1#include "G4NistManager.hh"
2
3auto* nm = G4NistManager::Instance();
4auto* air = nm->FindOrBuildMaterial("G4_AIR");
G4NistManagerで、
NIST(National Institute of Standards and Technology)のデータベースにある元素や物質を取得できます。
物質を取得したい(G4NistManager::FindOrBuildMaterial)
1auto* air = nm->FindOrBuildMaterial("G4_AIR");
2auto* water = nm->FindOrBuildMaterial("G4_WATER");
3auto* vacuum = nm->FindOrBuildMaterial("G4_Galactic");
G4NistManager::FindOrBuildMaterialメソッドで
物質(G4Material)を取得できます。
利用可能なマテリアル名はGeant4 Material Databaseを参照してください。
一般的な物質が欲しい場合は、まずこのデータベースから探すのがよいと思います。
元素を取得したい(G4NistManager::FindOrBuildElement)
1auto* H = nm->FindOrBuildElement("G4_H")
2auto* O = nm->FindOrBuildElement("G4_O")
G4NistManager::FindOrBuildElementメソッドで
元素(G4Element)を取得できます。
NISTデータベースには水素(G4_H)からカリフォルニウムまでの元素が登録されています。
特殊な材料を調達したい(G4NistManager::BuildMaterialWithNewDensity)
1auto nm = G4NistManager::Instance();
2nm->FindOrBuildMaterial("G4_Ar"); // density = 1.66201 mg/cm3
3G4double density = 1.782 * mg/cm3;
4nm->BuildMaterialWithNewDensity("Ar_heavy", "G4_Ar", density);
BuildMaterialWithNewDensityメソッドで、NISTの材料データベースを基にしながら、密度などを変更できます。
一括で調達したい
付属サンプルB5のDetectorConstructionではConstructMaterials()関数を作成し、利用する材料を一括して調達しています。
それをDetectorConstruction::Construct()の中で呼び出し、ジオメトリを作成するときはG4Material::GetMaterial("材料名")で作成しています。
これはそのまま真似するとよいなと思ったので、関連するソースを抜粋してみました。
1// \file プロジェクト名/include/DetectorConstruction.hh
2// \brief Definition of the プロジェクト名::DetectorConstruction class
3
4#ifndef プロジェクト名_DetectorConstruction_h
5#define プロジェクト名_DetectorConstruction_h 1
6
7// 必要なG4ヘッダーをインクルードする
8
9namespace プロジェクト名
10{
11 class DetectorConstruction : public G4VUserDetectorConstruction
12 {
13 public:
14 G4PhysicalVolume* Construct() override;
15 void ConstructMaterials();
16 }
17}
18
19#endif
1// \file プロジェクト名/src/DetectorConstruction.cc
2// \brief Implementation of the プロジェクト名::DetectorConstruction class
3
4#include "DetectorConstruction.hh"
5
6// 必要なG4ヘッダーをインクルードする
7
8namespace プロジェクト名
9{
10 G4VPhysicalVolume* DetectorConstruction::Construct()
11 {
12 ConstructMaterials(); // <-- 材料を一括で調達
13 auto air = G4Material::GetMaterial("G4_AIR");
14
15 // 検出器のジオメトリを定義する
16 auto worldSolid = new G4Box(...);
17 auto worldLogical = new G4LogicalVolume(...);
18 auto worldPhysical = new G4PVPlacement(...);
19
20 // 最後はワールドをリターンする
21 return worldPhysical;
22 }
23
24 void DetectorConstruction::ConstructMaterials()
25 {
26 auto nistManager = G4NistManager::Instance();
27 // Air
28 nistManager->FindOrBuildMaterial("G4_AIR");
29 // Water
30 nistManager->FindOrBuildMaterial("G4_WATER");
31 // Vacuum (Galactic)
32 nistManager->FindOrBuildMaterial("G4_Galactic");
33 // Vacuum (Air with low density)
34 auto air = G4Material::GetMaterial("G4_AIR");
35 G4double density = 1.0e-5 * air->GetDensity();
36 nistManager->BuildMaterialWithNewDensity("AIR_LOW", "G4_AIR", density);
37
38 G4cout << G4endl << "The materials defined are : " << G4endl << G4endl;
39 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
40 }
41}