Measure the cobalt 60 decay with an HPGe detector to spectralize the energy

_Geant4 Version: geant4-11-02-patch-02 [MT] (21-June-2024)
_Operating System: Ubuntu 64bit
_Compiler/Version:_g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
_CMake Version: 3.22.1

I have implemented and visualized the HPGe geometry and even confirmed that gammas are interacting with the setup, but Iโ€™m not seeing any energy deposition in the HPGe crystal. I based my work on the rdecay01 example, but I canโ€™t figure out why this is happening. If I send my source code by email, would someone be willing to review it? Iโ€™ve been stuck on this for so long and have no idea what Iโ€™m missing. Pleaseโ€ฆ

DetectorConstruction.cc

#include "DetectorConstruction.hh"

#include "G4Box.hh"
#include "G4Tubs.hh"
#include "G4LogicalVolume.hh"
#include "G4NistManager.hh"
#include "G4PVPlacement.hh"
#include "G4VisAttributes.hh"
#include "G4SubtractionSolid.hh"
#include "G4UnionSolid.hh"
//#include "SensitiveDetector.hh"
#include "EdepSD.hh"
#include "G4SDManager.hh"
#include "G4SystemOfUnits.hh"

DetectorConstruction::DetectorConstruction()
 : G4VUserDetectorConstruction()
{}

DetectorConstruction::~DetectorConstruction()
{}

G4VPhysicalVolume* DetectorConstruction::Construct() {
  auto nist = G4NistManager::Instance();

  auto iron = nist->FindOrBuildMaterial("G4_Fe");

  G4double density = 1.35 * g/cm3;
    G4Material* soil = new G4Material("SoilWithoutCs", density, 8);
    G4Material* air  = nist->FindOrBuildMaterial("G4_AIR");

    // Elements (O๋Š” ์ •์˜๋งŒ ํ•ด ๋‘์…จ์œผ๋ฏ€๋กœ, ์›๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค)
    G4Element* Si = nist->FindOrBuildElement("Si");
    G4Element* Al = nist->FindOrBuildElement("Al");
    G4Element* Fe = nist->FindOrBuildElement("Fe");
    G4Element* Ca = nist->FindOrBuildElement("Ca");
    G4Element* Mg = nist->FindOrBuildElement("Mg");
    G4Element* Na = nist->FindOrBuildElement("Na");
    G4Element* K  = nist->FindOrBuildElement("K");

    // Add Elements to Soil (Cs ๋Š” ์ œ๊ฑฐ)
    soil->AddElement(Si, 0.66899981937);
    soil->AddElement(Al, 0.19899994627);
    soil->AddElement(Fe, 0.014799996004);
    soil->AddElement(Ca, 0.007299998029);
    soil->AddElement(Mg, 0.003499999055);
    soil->AddElement(Na, 0.014499996085);
    soil->AddElement(K,  0.023499993655);

    // ๊ณต๊ทน(air) ๋ถ„์œจ์„ ์›๋ž˜ 0.068399981532 ์—์„œ 2.7e-07 ๋งŒํผ ๋”ํ•ด ์ค๋‹ˆ๋‹ค
    soil->AddMaterial(air, 0.068399981532 + 2.7e-07);

  //
  // 1) World
  //
  auto solWorld = new G4Box("World", 3.0*m, 3.0*m, 4.0*m);
  auto matAir   = nist->FindOrBuildMaterial("G4_AIR");
  auto lvWorld  = new G4LogicalVolume(solWorld, matAir, "WorldLV");
  auto pvWorld  = new G4PVPlacement(
                      nullptr, G4ThreeVector(), lvWorld, "WorldPV",
                      nullptr, false, 0, true);
  auto visWorld = new G4VisAttributes(G4Colour(1,1,1));
  visWorld->SetForceWireframe(true);
  lvWorld->SetVisAttributes(visWorld);


  // -----------------------------
// ์™ธ๋ถ€ ์ฒ  ๋ฐ•์Šค (๋ชจ๋“  ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ๋ฅผ ๊ฐ์‹ธ๋Š” ์ƒ์ž)
// -----------------------------

// 1. ์™ธ๋ถ€ ๋ฐ•์Šค ํฌ๊ธฐ (3.0 ร— 2.4 ร— 2.4 m)
G4double outerFeX = 2.4 * m;
G4double outerFeY = 2.4 * m;
G4double outerFeZ = 3.0 * m;

// 2. ๋‘๊ป˜ 4T (4 mm)
G4double feThickness = 4.0 * mm;

// 3. ๋‚ด๋ถ€ ํฌ๊ธฐ ๊ณ„์‚ฐ
G4double innerFeX = outerFeX - 2 * feThickness;
G4double innerFeY = outerFeY - 2 * feThickness;
G4double innerFeZ = outerFeZ - 2 * feThickness;

// 4. Solid ์ƒ์„ฑ
G4Box* solidOuterFe = new G4Box("SolidOuterFe", outerFeX/2, outerFeY/2, outerFeZ/2);
G4Box* solidInnerFe = new G4Box("SolidInnerFe", innerFeX/2, innerFeY/2, innerFeZ/2);

// 5. Subtraction์œผ๋กœ ์†์ด ๋นˆ ์ฒ  ์ƒ์ž ์ƒ์„ฑ
G4SubtractionSolid* shellFeBox = new G4SubtractionSolid(
    "OuterFeShell", solidOuterFe, solidInnerFe, nullptr, G4ThreeVector());

// 6. ๋…ผ๋ฆฌ ๋ณผ๋ฅจ ์ •์˜
auto lvFeShell = new G4LogicalVolume(shellFeBox, iron, "FeShellLV");
auto visFe = new G4VisAttributes(G4Colour(0.6, 0.6, 0.6));
visFe->SetForceWireframe(true);
lvFeShell->SetVisAttributes(visFe);

// 7. ์›”๋“œ์— ๋ฐฐ์น˜ (์ค‘์•™ ์ •๋ ฌ)
new G4PVPlacement(nullptr, G4ThreeVector(), lvFeShell, "FeShellPV", lvWorld, false, 0, true);

// ์ดํ›„ IronBox, MyBox1, Cryostat1, MyBox2, Cryostat2๋Š” ๋‚ด๋ถ€์— ์ƒ๋Œ€ ์œ„์น˜๋กœ ๋ฐฐ์น˜ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
// ๊ธฐ์กด IronBox ๋ฐ Cryostat ์œ„์น˜ ์„ค์ • ์‹œ ๋ถ€๋ชจ ๋ณผ๋ฅจ์„ lvWorld โ†’ lvFeShell๋กœ ๋ณ€๊ฒฝํ•˜๊ณ ,
// ๋ฐฐ์น˜ ์œ„์น˜๋ฅผ ์ ์ ˆํžˆ ์˜คํ”„์…‹ํ•˜์—ฌ ์ค‘์•™์— ๋งž์ถ”๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜์„ธ์š”.

// ์˜ˆ์‹œ:
// new G4PVPlacement(..., G4ThreeVector(x, y, z), ..., lvFeShell, ...);


  //
  //  (๊ธฐ์กด IronBox, Soil ๋“ฑ์€ ๊ทธ๋Œ€๋กœ ๋‘์‹œ๊ณ โ€ฆ)

  // 1. ์žฌ๋ฃŒ ์„ค์ •

G4double thickness = 3.0 * mm;

// 2. ๋‚ด๋ถ€ ๋ฐ•์Šค (์†์ด ๋นˆ ๊ณต๊ฐ„ ํฌ๊ธฐ)
G4double innerX = 1.0 * m;
G4double innerY = (1.0 + 0.003) * m;
G4double innerZ = 1.0 * m;
G4Box* hollowBox = new G4Box("HollowBox", innerX / 2, innerY / 2, innerZ / 2);

// 3. ์™ธ๋ถ€ ๋ฐ•์Šค (์ฒ  ์žฌ์งˆ ๊ป๋ฐ๊ธฐ ํฌํ•จ ํฌ๊ธฐ)
G4double outerX = innerX + 2 * thickness;
G4double outerY = innerY + 2 * thickness;
G4double outerZ = innerZ + 2 * thickness;
G4Box* solidBox = new G4Box("SolidBox", outerX / 2, outerY / 2, outerZ / 2);

// 4. ๋‚ด๋ถ€ ๋ฐ•์Šค๋ฅผ ์œ„๋กœ 3mm ์˜ฌ๋ ค์„œ ๋šœ๊ป‘ ๋‘๊ป˜ ์ƒ์„ฑ
G4ThreeVector translation(0, 3 * mm, 0);

// 5. SubtractionSolid: solidBox - hollowBox = ์ฒ  ์ƒ์ž ๊ป๋ฐ๊ธฐ
G4SubtractionSolid* IronBoxSolid = new G4SubtractionSolid(
    "IronBox", solidBox, hollowBox, nullptr, translation);

// 6. ๋…ผ๋ฆฌ ๋ณผ๋ฅจ ์ƒ์„ฑ
G4LogicalVolume* logicIronBox = new G4LogicalVolume(IronBoxSolid, iron, "LogicIronBox");
auto visIB = new G4VisAttributes(G4Colour(0.6, 0.6, 0.6));
visIB->SetForceWireframe(true);
logicIronBox->SetVisAttributes(visFe);

// 7. ์›”๋“œ์— ์ฒ  ์ƒ์ž ๋ฐฐ์น˜
new G4PVPlacement(nullptr, G4ThreeVector(0, 0, 0),
                  logicIronBox, "IronBox", lvWorld, false, 0);

// =======================
//  ๋‚ด๋ถ€์— ํ† ์–‘ ์ถ”๊ฐ€
// =======================

// 8. ํ† ์–‘ ๋…ผ๋ฆฌ ๋ณผ๋ฅจ ์ •์˜
G4LogicalVolume* logicSoil = new G4LogicalVolume(hollowBox, soil, "LogicSoil");

// 9. ์‹œ๊ฐํ™”
auto soilVis = new G4VisAttributes(G4Colour(0.6, 0.4, 0.2, 0.8));
soilVis->SetForceSolid(true);
logicSoil->SetVisAttributes(soilVis);

// 10. ํ† ์–‘์„ ์ฒ  ์ƒ์ž์˜ ๋‚ด๋ถ€ ์ž์‹์œผ๋กœ ๋ฐฐ์น˜
new G4PVPlacement(nullptr, translation,  // ๋™์ผํ•œ translation ์ ์šฉ
                  logicSoil, "SoilVolume", lvWorld, false, 0);

  //

  //
  // 2) Detector holder: Lead Box ("MyBox")
  //
  G4double halfX = 14.0*cm/2, halfY = 13.0*cm/2, halfZ = 16.0*cm/2;
  G4double num   = -200.0*mm - (outerZ/2);   // ์›๋ž˜ offset ๊ฐ’
  G4Box*    detBox  = new G4Box("detBox", halfX, halfY, halfZ);
  auto      matPb   = nist->FindOrBuildMaterial("G4_Pb");
  auto      lvBox   = new G4LogicalVolume(detBox, matPb, "MyBoxLV");
  new G4PVPlacement(
    nullptr,
    G4ThreeVector(0,0,-110.0*mm + num),
    lvBox, "MyBoxPV", lvWorld, false, 0, true);

  //
  // 3) Cryostat shell
  //
  G4double cryo_or = 52.5*mm;
  G4double cryo_th =  1.6*mm;
  G4double cryo_bh = 48.4*mm;
  G4double cryo_ct =  1.6*mm;
  G4Tubs* cryoBody = new G4Tubs("CryoBody",
                                cryo_or-cryo_th, cryo_or,
                                cryo_bh/2, 0.*deg, 360.*deg);
  
  G4Tubs* cryoCap  = new G4Tubs("CryoCap",
                                0, cryo_or, cryo_ct/2, 0.*deg,360.*deg);
  auto cryoShell   = new G4UnionSolid(
                        "CryostatShell", cryoBody, cryoCap,
                        nullptr, G4ThreeVector(0,0,cryo_bh/2));
  auto lvCryo      = new G4LogicalVolume(cryoShell,
                                         nist->FindOrBuildMaterial("G4_Al"),
                                         "CryostatLV");
  auto visCryo     = new G4VisAttributes(G4Colour(1,1,0));
  visCryo->SetForceSolid(true);
  lvCryo->SetVisAttributes(visCryo);

  // Place Cryostat in World
  G4double z_box_top = -110.0*mm + num + halfZ ; //140mm (Z)
  G4double z_cryo    = z_box_top + (cryo_bh + cryo_ct)/2.0;
  new G4PVPlacement(
    nullptr,
    G4ThreeVector(0,0, z_cryo),
    lvCryo, "CryostatPV", lvWorld, false, 0, true);

  //
  // 4) Cryo-Vacuum inside Cryostat
  //
  G4double vac_margin = 0.01*mm;
  G4double vac_r  = cryo_or - cryo_th - vac_margin;
  G4double vac_h  = cryo_bh/2.0 - vac_margin;
  G4Tubs* vacSolid = new G4Tubs("CryoVacuumSolid",
                                0, vac_r, vac_h, 0.*deg,360.*deg);
  auto lvVac      = new G4LogicalVolume(vacSolid,
                                        nist->FindOrBuildMaterial("G4_Galactic"),
                                        "CryoVacuumLV");
  new G4PVPlacement(
    nullptr,
    G4ThreeVector(),
    lvVac, "CryoVacuumPV", lvCryo, false, 0, true);

  //
  // 5) IR-Shield shell inside Vacuum
  //
  G4double ir_or = 50.9*mm;
  G4double ir_th = 1.5*mm;
  G4double ir_bh = (44.4)*mm;
  G4double ir_ct = (1.5)*mm;
  G4Tubs* irBody = new G4Tubs("IRBody",
                              ir_or-ir_th, ir_or,
                              ir_bh/2, 0.*deg,360.*deg);
  
  G4Tubs* irCap  = new G4Tubs("IRCap",
                              0, ir_or, ir_ct/2, 0.*deg,360.*deg);
  auto irShell   = new G4UnionSolid(
                      "IRShieldShell", irBody, irCap,
                      nullptr, G4ThreeVector(0,0,ir_bh/2));
  auto lvIR      = new G4LogicalVolume(irShell,
                                        nist->FindOrBuildMaterial("G4_Al"),
                                        "IRShieldLV");
  auto visIR     = new G4VisAttributes(G4Colour(0.5,0.5,0.5));
  visIR->SetForceSolid(true);
  lvIR->SetVisAttributes(visIR);

  // Place IR-Shield shell
  G4double z_ir_in_cryo = -(cryo_bh - ir_bh)/2.0;
  new G4PVPlacement(
    nullptr,
    G4ThreeVector(0,0,z_ir_in_cryo),
    lvIR, "IRShieldPV", lvVac, false, 0, true);

  //
  // 6) IR-Shield Vacuum inside IR-Shield shell
  //
  G4double irVac_margin = 0.01*mm;
  G4double irVac_r  = ir_or - ir_th - irVac_margin;
  G4double irVac_h  = ir_bh/2.0 - irVac_margin;
  G4Tubs* irVacSolid = new G4Tubs("IRShieldVacuumSolid",
                                  0, irVac_r, irVac_h, 0.*deg,360.*deg);
  auto lvIRVac = new G4LogicalVolume(irVacSolid,
                                      nist->FindOrBuildMaterial("G4_Galactic"),
                                      "IRShieldVacuumLV");
  new G4PVPlacement(
    nullptr,
    G4ThreeVector(),
    lvIRVac, "IRShieldVacuumPV", lvIR, false, 0, true);

  //
  // 7) Crystal inside IR-Shield Vacuum
  //
  G4double cry_r = 42.5*mm;
  G4double cry_h = 30.0*mm;
  G4Tubs* crySolid = new G4Tubs("CrystalSolid",
                                0, cry_r, cry_h/2, 0.*deg,360.*deg);
  G4Tubs* core     = new G4Tubs("CoreSolid",
                                0, 3.5*mm,  9.0*mm, 0.*deg,360.*deg);
  auto cryFinal    = new G4SubtractionSolid(
                        "CrystalWithCore", crySolid, core,
                        nullptr, G4ThreeVector(0,0,-6.0*mm));
  auto lvCrystal   = new G4LogicalVolume(cryFinal,
                                         nist->FindOrBuildMaterial("G4_Ge"),
                                         "CrystalLV");
  auto visCry      = new G4VisAttributes(G4Colour(0,1,1));
  visCry->SetForceWireframe(true);
  lvCrystal->SetVisAttributes(visCry);

  // place Crystal
  G4double z_crystal_in_ir =  4.1*mm;
  new G4PVPlacement(
    nullptr,
    G4ThreeVector(0,0,z_crystal_in_ir),
    lvCrystal, "CrystalPV", lvIRVac, false, 0, true);

  //
  // 8) attach SensitiveDetector to CrystalPV
  //

    // Second Geometry!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    //------------------------------

// ์•„๋ž˜๋Š” Z-์ถ•๊ณผ Z+์ถ• ์–‘๋ฐฉํ–ฅ์— Cryostat + IRShield + Crystal ๊ตฌ์กฐ๋ฅผ ๊ฐ๊ฐ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ฐฐ์น˜ํ•œ ์ „์ฒด ์ฝ”๋“œ ์ค‘์—์„œ
// Z+ ๊ตฌ์กฐ๋ฅผ ์œ„ํ•œ **๋…๋ฆฝ์ ์ธ ๋…ผ๋ฆฌ ๋ณผ๋ฅจ**์„ ์ƒ์„ฑํ•˜๊ณ , ์ค‘๋ณต ์—†์ด ๋ฐฐ์น˜ํ•˜๋Š” ๋ถ€๋ถ„๋งŒ ์ •๋ฆฌํ•œ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

// Z+ ๋ฐฉํ–ฅ Cryostat ๋‚ด๋ถ€ ๊ตฌ์กฐ๋ฅผ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ฐฐ์น˜ํ•˜๊ธฐ ์œ„ํ•œ ์ „์ฒด ์ฝ”๋“œ (์ค‘๋ณต ์ œ๊ฑฐ ํฌํ•จ)

// Z+ ๋ฐฉํ–ฅ Cryostat ๋‚ด๋ถ€ ๊ตฌ์กฐ๋ฅผ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ฐฐ์น˜ํ•˜๊ธฐ ์œ„ํ•œ ์ „์ฒด ์ฝ”๋“œ (์ค‘๋ณต ์ œ๊ฑฐ ํฌํ•จ)

// -----------------------------
// 1. Z+ ๋ฐฉํ–ฅ ํšŒ์ „ ํ–‰๋ ฌ
// -----------------------------
auto rot180 = new G4RotationMatrix();
rot180->rotateY(180.*deg);

// -----------------------------
// 2. Z+ ๋ฐฉํ–ฅ ๋ฐ•์Šค ๋ฐฐ์น˜
// -----------------------------
G4double z_box_center = -110.0*mm + num;
G4double z_cryo_2 = -z_cryo;
new G4PVPlacement(nullptr, G4ThreeVector(0, 0, -z_box_center), lvBox, "MyBoxPV_2", lvWorld, false, 1, true);

// -----------------------------
// 3. Z+ ๋ฐฉํ–ฅ Cryostat ๋ฐ ๋‚ด๋ถ€ ๊ตฌ์กฐ ๋ณ„๋„ ๋…ผ๋ฆฌ ๋ณผ๋ฅจ์œผ๋กœ ๊ตฌ์„ฑ ๋ฐ ๋ฐฐ์น˜
// -----------------------------
auto lvCryo2 = new G4LogicalVolume(cryoShell, nist->FindOrBuildMaterial("G4_Al"), "CryostatLV_2");
auto visCryo2 = new G4VisAttributes(G4Colour(1,1,0));
visCryo2->SetForceWireframe(true);
lvCryo2->SetVisAttributes(visCryo2);

G4Tubs* vacSolid2 = new G4Tubs("CryoVacuumSolid_2", 0, vac_r, vac_h, 0.*deg,360.*deg);
auto lvVac2 = new G4LogicalVolume(vacSolid2, nist->FindOrBuildMaterial("G4_Galactic"), "CryoVacuumLV_2");

G4Tubs* irBody2 = new G4Tubs("IRBody_2", ir_or-ir_th, ir_or, ir_bh/2, 0.*deg,360.*deg);
G4Tubs* irCap2 = new G4Tubs("IRCap_2", 0, ir_or, ir_ct/2, 0.*deg,360.*deg);
auto irShell2 = new G4UnionSolid("IRShieldShell_2", irBody2, irCap2, nullptr, G4ThreeVector(0,0,ir_bh/2));
auto lvIR2 = new G4LogicalVolume(irShell2, nist->FindOrBuildMaterial("G4_Al"), "IRShieldLV_2");
auto visIR2 = new G4VisAttributes(G4Colour(0.5,0.5,0.5));
visIR2->SetForceWireframe(true);
lvIR2->SetVisAttributes(visIR2);

G4Tubs* irVacSolid2 = new G4Tubs("IRShieldVacuumSolid_2", 0, irVac_r, irVac_h, 0.*deg,360.*deg);
auto lvIRVac2 = new G4LogicalVolume(irVacSolid2, nist->FindOrBuildMaterial("G4_Galactic"), "IRShieldVacuumLV_2");

G4Tubs* crySolid2 = new G4Tubs("CrystalSolid_2", 0, cry_r, cry_h/2, 0.*deg,360.*deg);
G4Tubs* core2     = new G4Tubs("CoreSolid_2", 0, 3.5*mm, 9.0*mm, 0.*deg,360.*deg);
auto cryFinal2 = new G4SubtractionSolid("CrystalWithCore_2", crySolid2, core2, nullptr, G4ThreeVector(0,0,-6.0*mm));
auto lvCrystal2 = new G4LogicalVolume(cryFinal2, nist->FindOrBuildMaterial("G4_Ge"), "CrystalLV_2");
auto visCry2 = new G4VisAttributes(G4Colour(0, 1, 1));
visCry2->SetForceWireframe(true);
lvCrystal2->SetVisAttributes(visCry2);

new G4PVPlacement(rot180, G4ThreeVector(0, 0, z_cryo_2), lvCryo2, "CryostatPV_2", lvWorld, false, 1, true);
new G4PVPlacement(nullptr, G4ThreeVector(), lvVac2, "CryoVacuumPV_2", lvCryo2, false, 1, true);
new G4PVPlacement(nullptr, G4ThreeVector(0, 0, z_ir_in_cryo), lvIR2, "IRShieldPV_2", lvVac2, false, 1, true);
new G4PVPlacement(nullptr, G4ThreeVector(), lvIRVac2, "IRShieldVacuumPV_2", lvIR2, false, 1, true);
new G4PVPlacement(nullptr, G4ThreeVector(0, 0, z_crystal_in_ir), lvCrystal2, "CrystalPV_2", lvIRVac2, false, 1, true);

// Sensitive Detector ์—ฐ๊ฒฐ
// auto sd1 = new SensitiveDetector("CrystalSD1",0);
// auto sd2 = new SensitiveDetector("CrystalSD2",1);
// G4SDManager::GetSDMpointer()->AddNewDetector(sd1);
// G4SDManager::GetSDMpointer()->AddNewDetector(sd2);

// lvCrystal->SetSensitiveDetector(sd1);
// lvCrystal2->SetSensitiveDetector(sd2);

auto edepSD = new EdepSD("EdepSD");
G4SDManager::GetSDMpointer()->AddNewDetector(edepSD);

// Crystal ๋…ผ๋ฆฌ๋ณผ๋ฅจ์— ๋ถ™์ด๊ธฐ
lvCrystal->SetSensitiveDetector(edepSD);
lvCrystal2->SetSensitiveDetector(edepSD);


return pvWorld;
}

EdepSD.cc

// EdepSD.hh
#include "G4VSensitiveDetector.hh"
#include "G4SDManager.hh"   
#include "EdepHit.hh"
#include "G4AnalysisManager.hh"
#include "G4Gamma.hh"

class EdepSD : public G4VSensitiveDetector {
public:
  EdepSD(const G4String& name)
    : G4VSensitiveDetector(name),
      fHitsCollection(nullptr) {
    collectionName.insert("EdepCollection");
  }
  virtual ~EdepSD(){}

  virtual void Initialize(G4HCofThisEvent* hce) override {
    fHitsCollection = new EdepHitsCollection(SensitiveDetectorName, collectionName[0]);
    G4int hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
    hce->AddHitsCollection(hcID, fHitsCollection);
  }


  virtual G4bool ProcessHits(G4Step* step, G4TouchableHistory*) override {
   auto particle = step->GetTrack()->GetDefinition();
  //if (particle != G4Gamma::Definition()) return false;  // ๊ฐ๋งˆ๊ฐ€ ์•„๋‹ˆ๋ฉด ๋ฌด์‹œ

  G4double edep = step->GetTotalEnergyDeposit();
  if (edep <= 0.) return false;

  // ํžˆํŠธ ์ปฌ๋ ‰์…˜์— ๋„ฃ๊ธฐ
  auto hit = new EdepHit();
  hit->SetEdep(edep);
  hit->SetPos(step->GetPreStepPoint()->GetPosition());
  fHitsCollection->insert(hit);

  // ๊ฐ๋งˆ ์นจ์ ๋งŒ ํžˆ์Šคํ† ๊ทธ๋žจ์— ๊ธฐ๋ก
  auto analysis = G4AnalysisManager::Instance();
  analysis->FillH1(10, edep);

  return true;
  }
private:
  EdepHitsCollection* fHitsCollection;
};

HistoManager.cc

#include "HistoManager.hh"
#include "G4UnitsTable.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

HistoManager::HistoManager()
{
  Book();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void HistoManager::Book()
{
  // Create or get analysis manager
  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
  analysisManager->SetDefaultFileType("csv");
  analysisManager->SetFileName(fFileName);
  analysisManager->SetVerboseLevel(1);
  analysisManager->SetActivation(true);     //enable inactivation of histograms
  
  // Define histograms start values
  const G4int kMaxHisto = 10;
  const G4String id[] = {"0","1","2","3","4","5","6","7","8","9","10"};
  const G4String title[] = 
          { "dummy",                                    //0
            "energy spectrum (%): e+ e-",               //1
            "energy spectrum (%): nu_e anti_nu_e",      //2
            "energy spectrum (%): gamma",               //3
            "energy spectrum (%): alpha",               //4
            "energy spectrum (%): ions",                //5
            "total kinetic energy per single decay (Q)",//6
            "momentum balance",                         //7
            "total time of life of decay chain",        //8
            "total visible energy in decay chain",       //9
            "SD Co60 Deposit"
          };

  // Default values (to be reset via /analysis/h1/set command)               
  G4int nbins = 100;
  G4double vmin = 0.;
  G4double vmax = 100.;

  // Create all histograms as inactivated 
  // as we have not yet set nbins, vmin, vmax
  for (G4int k=0; k<kMaxHisto; k++) {
    G4int ih = analysisManager->CreateH1(id[k], title[k], nbins, vmin, vmax);
    analysisManager->SetH1Activation(ih, false);
  }
}

This is how itโ€™s organized

Hello,

Code revision is not something people normally do in this forum as it can be VERY time consuming. I would suggest to brake your question into parts and Iโ€™m sure people will be more than happy to help.

Cheers,

/Pico

As a first pass, just post the Detector Construction and whatever file you are using to actually register the hits. The physics list would also not be bad but if you are just using rdecay01, it should be fine.
Last question, what about other sources?

Your version of Geant4 defaults to 1 year for tracking radiation sources. This should be set either in your main file or done in the macro:

/process/had/rdm/thresholdForVeryLongDecayTime 1.0e+60 year

If itโ€™s not too much trouble, could you take a look at the sauce?

Couple of quick comments.

  1. If a volume is fully enclosed by another volume you should just make that volume a daughter of the enclosing volume. This avoids unpredictable behavior and possible seg faults.
  2. I donโ€™t think you are histogramming what you want. Right now, whenever there is any interaction in that volume you will histogram that individual energy deposited. You should just sum up edep over the entire event, histogram it at the end, then reset it at the start of the next event which is easier to see done in rdecay02.
  3. Are you saving the hits collection elsewhere?
  4. RDecay01/02 disable the histograms by default, as you have in your code:
 for (G4int k=0; k<kMaxHisto; k++) {
    G4int ih = analysisManager->CreateH1(id[k], title[k], nbins, vmin, vmax);
    analysisManager->SetH1Activation(ih, false);
  }

Are you enabling your histogram somewhere in your code or in the macro?

Edit - Actually, your code doesnโ€™t even create the histogram. You have added the histogram details to the various arrays but you havenโ€™t incremented kMaxHisto to 11, so you arenโ€™t even creating the histogram. Even still, youโ€™d also have to activate it in your macro or you could hard code it to always be enabled by default (which is not advised).

1 Like

I was able to resolve it successfully thanks to you.