No energy deposited using Stepping and Scoring Volume

Hello everybody!
I am a beginner with Geant4 and I am struggling with Energy deposition using Stepping and scoring volumes. Hope someone can help me (:
I have followed step by step B1 example. Namely, what I have in stepping.src is the following:

void MySteppingAction::UserSteppingAction(const G4Step *step)
    if (!fScoringVolume) {
      const MyDetectorConstruction* detectorConstruction = static_cast<const MyDetectorConstruction*> (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
      fScoringVolume = detectorConstruction->GetScoringVolume();
    // get volume of the current step
    G4LogicalVolume *volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
    // collect energy deposited in this step
    if (volume == fScoringVolume) {
        G4double edep = step->GetTotalEnergyDeposit();
        G4cout << "Energy deposition: " << edep << G4endl;
    // check if we are in scoring volume
    if(volume != fScoringVolume)
    {G4cout << "NO SCORING VOLUME HIT"<< G4endl;

However, energy deposition is always 0, and “NO SCORING VOLUME HIT” appears, implying my volume is not the scoring one. I see the hits visually, and I also get the CopyNumber of the hit detector, but no energy deposited.

My setup consists in 6 Silicon detectors, which I created as cylinders located at different angles. Then I use GeneralParticleSource to produce alpha particles hitting them.
Since the main difference with B1 example for what concerns volumes are the detectors, I’ve started to think I am doing something wrong in associating the scoring volume.
What I did was creating a single LogicalVolume to which I associate the fScoringVolume

G4LogicalVolume* logicDetector = new G4LogicalVolume(solidDetector,SiO2,"Detector");
fScoringVolume= logicDetector;

and then associate this to the 6 PhysicalVolume with two for loops (I know this might not be the best implementation…)

for (G4int i = 1; i < n_raw +1; i++) {
            if (i==1){
                angle_raw = 30*deg;
            else {
                angle_raw = -30*deg;
            for (G4int j=0; j < n_det; j++) {
                if (j==0){
                    phi = 0*deg;
                    angley = 0.;
                    angleY =std::pow(-1,j)*angley*deg;
                    phi = std::pow(-1,j)*angle_rot*deg;
                    angley = 45.;
                    angleY =std::pow(-1,j)*angley*deg;     
                G4RotationMatrix *rotm  = new G4RotationMatrix;
                G4ThreeVector u = G4ThreeVector(std::cos((angle_raw))*std::sin(phi), std::sin(angle_raw),  std::cos(angle_raw)*std::cos(phi));
                G4ThreeVector position = distance*u;
                new G4PVPlacement(rotm,
                            logicDetector,            //its logical volume
                            "Detector",             //its name
                            logicWorld,             //its mother volume
                            false,                 //no boolean operation
                            2*i+j*3,                 //copy number i*j+i
                            fCheckOverlaps);       // checking overlaps

Could it be that this way of creating the physical volumes is causing issues with the scoring volume? Or do you have any other idea of what can cause this or suggestions to find the problem’s origin?

Thank you very much!

_Geant4 Version:11.0.3
_Operating System:MacOS

What do you mean by, you get the CopyNumber of the hit detector? Is there a seperate print statement elsewhere that prints that information for you?

Also, are you able to read every print statement that your program outputs? Is it possible that some of them read "Energy deposition: " but it is lost in the thousands of other statements that read “NO SCORING VOLUME HIT”? You could try commenting out the 2nd print statement statement to see if this is the case.

Thanks for your answer!

As for the CopyNumber, yes, I have a separate print statement in my SensitiveDetector::ProcessHits class. Namely:

//To get detector copynumber
    const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();

    G4int copyNo = touchable->GetCopyNumber();
    G4cout <<"Copy number: " << copyNo <<G4endl;

Also, I have created ROOT file where I store both this information and the energy deposited, which again is always zero. I have then inserted the print statement for the deposited energy to check it was not just a problem of the root output.

Same for the “NO SCORING VOLUME HIT” statement. I have put it there later to pinpoint whether the issue was in that part of the code. I have tried also with small number of alphas, I get CopyNumber, but no Energy deposited.

I also tried printing the Energy Deposited before writing it in the root output, and this is printed, but equal to 0:

void MyEventAction::EndOfEventAction(const G4Event*)
    // accumulate statistics in run action
    G4AnalysisManager *man = G4AnalysisManager::Instance();
    G4cout << "Energy deposition FINAL: " << fEdep << G4endl;

So, in short, when I run without the “NO SCORING VOLUME HIT” print I get:
Copy number: xx
Energy deposition FINAL: 0

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.