材料を調達したい(G4NistManager

1#include "G4NistManager.hh"
2
3G4NistManager *nistManager = new G4NistManager::GetInstance();
4
5G4Element *H = nistManager->FindOrBuildElement("G4_H")
6G4Element *O = nistManager->FindOrBuildElement("G4_O")
7
8G4Material *H2O = nistManager->FindOrBuildMaterial("G4_WATER")
9G4Material *Air = nistManager->FindOrBuildMaterial("G4_AIR")

G4NistManagerを使って、NISTの材料データベースにある元素や化合物などを調達できます。 元素(G4Element)が欲しい時はFindOrBuildElementメソッド、 物質(G4Material)が欲しい時はFindOrBuildElementメソッドを使います。

利用可能なマテリアル名はGeant4 Material Databaseを参照してください。

水素(G4_H)からカリフォルニウムまでの元素や、 水(G4_WATER)、空気(G4_AIR)、 素粒子・原子核実験でよく利用するような材料(G4_lXeG4_PbWO4G4_STAINLESS-STEELG4_Galactic(=真空))なども定義されています。

一般的な物質が欲しい場合は、まずこのリストから探すのがよいと思います。

特殊な材料を調達したい(BuildMaterialWithNewDensity

1auto nistManager = G4NistManager::Instance();
2nistManager->FindOrBuildMaterial("G4_Ar");  // density = 1.66201 mg/cm3
3G4double density = 1.782 * mg/cm3;
4nistManager->BuildMaterialWithNewDensity("Ar_heavy", "G4_Ar", density);

G4NistManager::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}