How to define phantomContainer as SD in DICOM example

HI:

I’ve been using the DICOM example recently, and I want to output information about where the particles are in the model. However, it seems that the G4VPrimitiveScorer cannot extract the particle location information according to my knowledge.

So I’m going to define phantomContainer as SD to get information about where the particles are going into the phantomContainer. Here are the changes I made to the DICOM sample program.

#ifndef DicomSD_h
#define DicomSD_h 1
#include "G4VSensitiveDetector.hh"
#include "DicomHit.hh"
class G4Step;
class G4HCofThisEvent;
class G4TouchableHistory;

class DicomSD : public G4VSensitiveDetector
{
  public:
    DicomSD(G4String name);
    ~DicomSD() override;

    void Initialize(G4HCofThisEvent*HCE) override;
    G4bool ProcessHits(G4Step*aStep,G4TouchableHistory*ROhist) override;

  private:
    HadCalorimeterHitsCollection* fHitsCollection = nullptr;
    G4int fHCID = -1;
};
#endif
ooooo0ooooo........ooooo0ooooo........ooooo0ooooo........ooooo0ooooo

#include "DicomSD.hh"
#include "DicomHit.hh"
#include "G4HCofThisEvent.hh"
#include "G4TouchableHistory.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4SDManager.hh"
#include "G4ios.hh"

DicomSD::DicomSD(G4String name)
: G4VSensitiveDetector(name)
{
 
  collectionName.insert("DicomColl");
  G4cout<<"-----------DicomSD-----------"<<G4endl;
}

DicomSD::~DicomSD()
{}

void DicomSD::Initialize(G4HCofThisEvent* hce)
{
  fHitsCollection
    = new HadCalorimeterHitsCollection(SensitiveDetectorName,collectionName[0]);
  if (fHCID<0) {
    fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
  }
  
  hce->AddHitsCollection(fHCID,fHitsCollection);
  fHitsCollection->insert(new DicomHit());
  
  G4cout<<"-----------DicomSD::Initialize-----------"<<G4endl;



}

G4bool DicomSD::ProcessHits(G4Step* step, G4TouchableHistory*)
{
  
  
  G4cout<<"-------DicomSD::ProcessHits-------"<<G4endl;

  return true;
}


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

  auto voxelSD = new DicomSD("voxelsd");
  G4SDManager::GetSDMpointer()->AddNewDetector(voxelSD);
  SetSensitiveDetector("phantomContainer",voxelSD);

I encountered a problem at runtime. After creating the SD, the prompts in DicomSD::DicomSD and DicomSD::Initialize at runtime were displayed normally on the terminal, but the messages on DicomSD::ProcessHits were not. I think the representative program skipped this when it was running.

Therefore, I would like to ask the experts whether the G4VPrimitiveScorer can extract the particle location information, so that I can avoid to define the SD detector again. If the G4VPrimitiveScorer is unable to extract particle information, may I ask if there is any problem in the SD detector I defined that caused the program to skip the DicomSD::ProcessHits function?

Thank you for your reply. I really need your help.

I understand that you want the step position in the global system of reference. If you use the phantom container as SD no hits will be created because tracks are never in phantom container volume but in the voxel phantom (which fully fill the container). You can extract that information from G4StepPoint with the code here which get the stepPoint position in the container system of reference (use a number different than 1 if phantom is displaced or rotated w.r.t. world)

G4ThreeVector localPos = GetLocalNFromGlobalPos( aStep->GetPreStepPoint()->GetPosition(), aStep->GetPreStepPoint()->GetTouchable()->GetHistory(), 1);


G4ThreeVector GetLocalNFromGlobalPos( const G4ThreeVector globalPos, const G4NavigationHistory* navHis, G4int ancestorLevel )
{
const G4AffineTransform transform = navHis->GetTransform(ancestorLevel);
G4ThreeVector localPos = transform.TransformPoint(globalPos);
}

1 Like

Thank you for your reply, I will try the method you said, this reply is really important to me.

According to your suggestion, should I define Voxel Phantom as SD, and then use G4StepPoint in the ProcessHits function of this SD to obtain the particle position information? Thank you again for your answer.

Right, and myy code will give you coordiantes in the container system of reference