Message: Re: Clear the memory allocated for G4VPrimitiveScorer? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Re: Clear the memory allocated for G4VPrimitiveScorer? 

Forum: Biasing and Scoring
Re: Question Clear the memory allocated for G4VPrimitiveScorer? (Clare Huang)
Re: None Re: Clear the memory allocated for G4VPrimitiveScorer? (Tsukasa Aso)
Re: None Re: Clear the memory allocated for G4VPrimitiveScorer? (Clare Huang)
Date: 07 May, 2018
From: Philipp Roser <Philipp Roser>

Hello everybody,

first of all, I apologize for reviving this old conversation but I somehow feel like I am encountering a very similar problem.

I am also adapting the example RE02 to my needs and tracked the dose deposition inside a voxel phantom and a CSi detector until now (using G4PSDoseDeposit3D). Everything worked just fine and I was able to easily run simulations of 1e8 gamma particles.

Now, I am further interested in tracking the kinetic energy of incident photons in each voxel. Since I found no primitive scorer that suited my needs exactly, I decided to implement one on my own. Therefore I derived a KineticEnergyScorer[3D] from G4VPrimitiveScorer. To bypass any complications I simply copied and pasted the G4PSNofSecondary[3D] scorer IIRC and only altered the ProcessHits method to the following:

  if ( aStep->GetTrack()->GetParticleDefinition()->GetParticleSubType() != "photon" ) return FALSE;
  if (!aStep->IsFirstStepInVolume()) return FALSE;
  G4double kinetic = aStep->GetPreStepPoint()->GetKineticEnergy();
  if (kinetic == 0.) return FALSE;
  G4int index = GetIndex(aStep);
  EvtMap->add(index, kinetic);
  return TRUE;

The implementation is pretty straight-forward; only photons that just enter the voxel are considered. This is how I register my specific scorer in RE02DetectorConstruction::ConstructSDandField:

//m_FD->RegisterPrimitive(new G4PSDoseDeposit3D(G4String("TotalDose"),m_voxel_detector_list[i]->get_voxel_num_x(),m_voxel_detector_list[i]->get_voxel_num_y(),m_voxel_detector_list[i]->get_voxel_num_z()));
    m_FD->RegisterPrimitive(new KineticEnergyScorer3D(G4String("TotalEKin"),m_voxel_detector_list[i]->get_voxel_num_x(),m_voxel_detector_list[i]->get_voxel_num_y(),m_voxel_detector_list[i]->get_voxel_num_z()));

Everything compiles and runs just fine for few primary particles (1e4). However, increasing the number of primaries to e.g. 1e7, the RAM on my CPU (8GB) is quickly filled up. Even an HPC Cluster node with 32 GB RAM is filled quickly. I assumed self-imposed memory leaks at first (for I know there are certainly some new calls without delete) and checked my program with valgrind.

Therefore I altered the above two lines such that only one scorer is commented in at once. Surprisingly, the valgrind log is identical for both configurations. Thus I concluded that my implementation of KineticEnergyScorer3D is not flawed in principal.

This is the point where I started searching this forum. I thought maybe a self-implemented scorer needs to be 'introduced/initialized' in the same way as UserActions for example. After reading your conversation I came to the conclusion that Clare potentially had the same issue, that only got 'disguised' by the fact that she used 28 scorers at once, whereas I have only one active scorer at once (2 in sum considering patient and detector).

I am well aware that I could carry out multiple simulations with fewer photons, but 1) I would rather solve the problem and 2) I intend to run simulations of >1e9 photons thus single simulations of 1e8 photons are my personal pain barrier. Does anyone have an idea how to solve my problem? I hope I gave a comprehensible explanation. If you need additional code or information don't hesitate to contact me.

Thanks in advance.

Best Philipp

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Feedback: Re: Clear the memory allocated for G4VPrimitiveScorer?   (Pedro Arce - 08 May, 2018)
2 None: Re: Clear the memory allocated for G4VPrimitiveScorer?   (Makoto Asai - 08 May, 2018)
1 Question: Re: Clear the memory allocated for G4VPrimitiveScorer?   (Philipp Roser - 30 Jul, 2018)
(_ Feedback: Re: Clear the memory allocated for G4VPrimitiveScorer?   (Jonathan Madsen - 30 Jul, 2018)
(_ Agree: Re: Clear the memory allocated for G4VPrimitiveScorer?   (Philipp Roser - 30 Jul, 2018)
 Add Message Add Message
to: "Re: Clear the memory allocated for G4VPrimitiveScorer?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews