Hi jrellin,
Please let me walk you through the process, forgive me if this is too much. Allow me to share my codes with you. The following code is for my SensitiveDetector.cc,
#include "SensitiveDetector.hh"
//Initialize static variable (this must remain outside of constructor)
G4double SensitiveDetector::fRunTotalEnergy = 0.;
SensitiveDetector::SensitiveDetector(G4String name) : G4VSensitiveDetector(name)
{
fTotalEnergy = 0.;
}
SensitiveDetector::~SensitiveDetector()
{
}
void SensitiveDetector::Initialize(G4HCofThisEvent*)
{
// Reset for new event
fTotalEnergy = 0.;
// Resets run total energy at start of first event.
G4int eventID = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
if(eventID == 0) {
fRunTotalEnergy = 0.;
}
}
G4bool SensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*)
{
// Get energy deposited in this step
G4double edep = step->GetTotalEnergyDeposit();
if(edep>0)
{
// Add to fTotalEnergy
fTotalEnergy += edep;
}
return true;
}
void SensitiveDetector::EndOfEvent(G4HCofThisEvent*)
{
//Accumulate to run total energy and check; if last event, print the result.
fRunTotalEnergy += fTotalEnergy;
G4int currentEvent = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
G4int totalEvents = G4RunManager::GetRunManager()->GetNumberOfEventsToBeProcessed();
if (currentEvent == totalEvents - 1) {
// Only print from the container detector
if (GetName() == "ContainerLVDetector") {
G4cout << "=== RUN COMPLETE ===" << G4endl;
G4cout << "Total Events: " << totalEvents << G4endl;
G4cout << "Total Energy Deposited in Run: " << fRunTotalEnergy << " MeV" << G4endl;
G4cout << "===================" << G4endl;
}
}
}
I attached this code to the ConstructSDandField in my DetectorConstruction as such,
void DetectorConstruction::ConstructSDandField()
{
//SD manager must be created here only once
G4SDManager* SDman = G4SDManager::GetSDMpointer();
//Sensitive detector for containerLV
SensitiveDetector *detector_containerLV = new SensitiveDetector("ContainerLVDetector");
containerLV->SetSensitiveDetector(detector_containerLV);
SDman->AddNewDetector(detector_containerLV);
//Sensitive detector for Cardboard
SensitiveDetector *detector_shellLogic = new SensitiveDetector("ShellLogicDetector");
shellLogic->SetSensitiveDetector(detector_shellLogic);
SDman->AddNewDetector(detector_shellLogic);
//Sensitive detector for Foam
SensitiveDetector *detector_foamLogic = new SensitiveDetector("FoamLogicDetector");
foamLogic->SetSensitiveDetector(detector_foamLogic);
SDman->AddNewDetector(detector_foamLogic);
//Sensitive detector for Vial
SensitiveDetector *detector_vialLV = new SensitiveDetector("VialLVDetector");
vialLV->SetSensitiveDetector(detector_vialLV);
SDman->AddNewDetector(detector_vialLV);
//Sensitive detector for Water Phantom
SensitiveDetector *detector_logicWater = new SensitiveDetector("LogicWaterDetector");
logicWater->SetSensitiveDetector(detector_logicWater);
SDman->AddNewDetector(detector_logicWater);
}
As you have already anticipated, I have many daughter volumes (2*256 volumes) that are replicated but the whole package consists of 5 logical volumes as above. This is the way I assigned my sensitive detector to the logical volumes and for every run, I always get 0.97 TeV energy deposition.
At the same time, I tried to examine the same thing using command-line and here is what I wrote,
# Score the air container (single volume)
/score/create/realWorldLogVol ContainerLV
/score/quantity/energyDeposit containerEnergy
/score/close
# Score the cardboard shell (single volume)
/score/create/realWorldLogVol ShellLogical
/score/quantity/energyDeposit shellEnergy
/score/close
# Score the foam (2 pieces - will sum automatically)
/score/create/realWorldLogVol FoamLogical
/score/quantity/energyDeposit foamEnergy
/score/close
# Score all vial glass (all vials combined)
/score/create/realWorldLogVol VialLogical
/score/quantity/energyDeposit vialEnergy
/score/close
# Score all water (all water volumes combined)
/score/create/realWorldLogVol WaterLogical
/score/quantity/energyDeposit waterEnergy
/score/close
# Run simulation
/run/beamOn 1000000
# Dump all results to files
/score/dumpQuantityToFile ContainerLV containerEnergy container_energy.txt
/score/dumpQuantityToFile ShellLogical shellEnergy shell_energy.txt
/score/dumpQuantityToFile FoamLogical foamEnergy foam_energy.txt
/score/dumpQuantityToFile VialLogical vialEnergy vial_energy.txt
/score/dumpQuantityToFile WaterLogical waterEnergy water_energy.txt
# Print summary to console
/score/list
And the reported results are OK; I know that I have 256 water samples inside the package and the text file for water_energy.txt has 256 rows, reporting the energy deposition of all the volumes. Same is true for other logical volumes I assigned.
But the funny thing is, when I sum up all the energy depositions, I get 0.511 TeV not 0.97 TeV. No matter how many times I run, I’ll always get the same results. I wonder what is the cause?
My Issue Regarding Dosimetry:
As I mentioned before, to calculate the dose, I used to convert the energy deposition I got from the simulation to Joules and divide it manually by the mass of my package (the mass calculation is done by Geant4 and I double-checked it manually, no problem).
Dose via my SensitiveDetector energy deposition report: 6.34e-8 Gy.
Dose via command-line energy deposition report: 3.34e-8 Gy
I decided to write another command-line for dose and this is the macro file,
/run/initialize
# Score the air container (single volume)
/score/create/realWorldLogVol ContainerLV
/score/quantity/doseDeposit containerDose
/score/close
# Score the cardboard shell (single volume)
/score/create/realWorldLogVol ShellLogical
/score/quantity/doseDeposit shellDose
/score/close
# Score the foam (2 pieces - will sum automatically)
/score/create/realWorldLogVol FoamLogical
/score/quantity/doseDeposit foamDose
/score/close
# Score all vial glass (all vials combined)
/score/create/realWorldLogVol VialLogical
/score/quantity/doseDeposit vialDose
/score/close
# Score all water (all water volumes combined)
/score/create/realWorldLogVol WaterLogical
/score/quantity/doseDeposit waterDose
/score/close
# Run simulation
/run/beamOn 1000000
# Dump all results to files
/score/dumpQuantityToFile ContainerLV containerDose container_dose.txt
/score/dumpQuantityToFile ShellLogical shellDose shell_dose.txt
/score/dumpQuantityToFile FoamLogical foamDose foam_dose.txt
/score/dumpQuantityToFile VialLogical vialDose vial_dose.txt
/score/dumpQuantityToFile WaterLogical waterDose water_dose.txt
# Print summary to console
/score/list
As you can see, same assignment, but this time for dose. This also gives peculiar results. The reported dose for the whole package is 1.52e-5!! this almost 1000 times larger. I am very confused and I don’t know which method is giving me the correct dose.
Please assist me.