Energy deposition in example B1

Hello,
I’m just learning Geant4. I try to modify the B1 example and need to get the total amount of energy deposited, (for example, shoot 100000 10MeV photons into the scintillator), so I modified Steppingaction.cc (code listed below) and the data is saved to a file called record1.txt,

void B1SteppingAction::UserSteppingAction(const G4Step *step)
{
  if (step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume()->GetName() == "filter_8")
  {
    edepStep = step->GetTotalEnergyDeposit();
    tmp_record = tmp_record + edepStep;
  }

  if(step->GetTrack()->GetParentID() == 0 && step->GetTrack()->GetCurrentStepNumber() == 1)
  {
    KineticEnergy = step->GetTrack()->GetKineticEnergy();
    data3 << KineticEnergy << G4endl;
  }

my Eventaction.cc

using namespace std;
extern G4double tmp_record;
ofstream data1("./record1.txt");


B1EventAction::B1EventAction(B1RunAction *runAction)
    : G4UserEventAction(),
      fRunAction(runAction),
      fEdep(0.)
{
}


B1EventAction::~B1EventAction()
{
}


void B1EventAction::BeginOfEventAction(const G4Event *)
{
    tmp_record = 0.0;
}


void B1EventAction::EndOfEventAction(const G4Event *)
{
    if (tmp_record > 0)
    {
        data1 << tmp_record << G4endl;
      
    }
}

but after I plotted the energy deposition rate curve using the photon energy and the deposition energy obtained with the “step->GetTotalEnergyDeposit()” command, I found that my data is different from the data obtained by other authors of the paper exists. (as shown below)

the original picture of the paper
1Y7BCU5~JM0PIUJ8VS{SE
[Proc. of SPIE Vol. 8852 88521A-1]

I would like to get the energy deposition due to photoelectric absorption, but it seems that now I get the energy attenuation that the photons pass through the scintillator (the physicslists I used is QBBC).

Could I use the “step->GetTotalEnergyDeposit()” command to get data on the energy deposited by photoelectric absorption in the scintillator? If not, is there a way to get this information?

Thank you very much!
SHZONG

Yes, GetTotalEnergyDeposit should bring you the total energy deposited at each step.

Try to write your own classes that interact and transfer the data. Globals may lead to errors that are hard to track.

Hi,

yes, you can, at least if what you want to do is to get the energy deposited by electrons created by the photoelectric effect. In your Steppingaction.cc add

#include G4VProcess.hh

and in your UserSteppingAction

auto CreatorProc = step->GetTrack()->GetCreatorProcess();
if (CreatorProc && CreatorProc->GetProcessName()=="phot"){ //nullpointer for primary particle
    step->GetTotalEnergyDeposit();        
}

Cheers, Lorenzo

Hello dear lopezzot,
As you said, I added these code in my SteppingAction.cc

#include "G4VProcess.hh"

using namespace std;
G4double edepphot;
ofstream data("./record.txt");

void B1SteppingAction::UserSteppingAction(const G4Step *step)
{
...

  auto CreatorProc = step->GetTrack()->GetCreatorProcess();
  if (CreatorProc && CreatorProc->GetProcessName()=="phot"){ //nullpointer for primary particle
    edepphot = step->GetTotalEnergyDeposit();

    data << edepphot << G4endl;

  }

I tried to record these energy data to a file called “record.txt”. After a run, I found that the “record.txt” has just been modified but these is no data in “record.txt” .
Did I use the wrong way to record the data or are these any special methods to record data in Geant4?

Thanks for your time and consideration!
SHZONG

Hi,

have you checked that the statement

if (CreatorProc && CreatorProc->GetProcessName()=="phot")

is true at least once per event/run?
Otherwise, it means that in the volume you are considering there are no tracks created by the photoelectric process.

Cheers, Lorenzo

Hi dear lopezzot,
Here’s the code in my SteppingAction.cc

#include "G4VProcess.hh"

using namespace std;
G4double edepStep;
...
void B1SteppingAction::UserSteppingAction(const G4Step *step)
{
  if (step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume()->GetName() == "A1")
  {
    auto CreatorProc = step->GetTrack()->GetCreatorProcess();
    if (CreatorProc && CreatorProc->GetProcessName()=="phot")
    { //nullpointer for primary particle
        edepStep = step->GetTotalEnergyDeposit();
        tmp_record = tmp_record + edepStep;      
    }  

  }

}

And the code in my EventAction.cc

ofstream data1("./record1.txt");
...
void B1EventAction::BeginOfEventAction(const G4Event *)
{
    tmp_record = 0.0;
}


void B1EventAction::EndOfEventAction(const G4Event *)
{
    if (tmp_record > 0)
    {
        data1 << tmp_record << G4endl;
    }
}

“tmp_record” is the value that I use to record the energy deposited by electrons. “A1” is the scintillator I created. I tried to saved “tmp_record” in a file called “record1.txt” and got the value once an event.
My goal was recording the value only when physical processes occurred in the scintillator. But the value I got was very small. Did I skip too many physical processes?

Thanks for your time and consideration!
SHZONG