Scoring output with zeros from dumpQuantityToFile

Dear all,

I’m a beginner of Geant4 and I’m writing in this group about a problem I found into obtaining the results with the command-based scoring. My simulation case is a 2 GeV proton, hitting a cylindrical target from which it is followed the spallation process, with the production of neutrons.
I don’t have errors in the simulation. I created a macro with the command-based scoring commands to tally the neutron flux and the energy deposition, without discretization (/score/mesh/nBin 1 1 1 ). The problem is that the output file dumpQuantityToFile returns zeros as the result for scoring of flux and energy deposition.

Here below, the macro tallies.mac called by the runManager to run beamOn and to obtain the energy deposition in the cylindrical target:

#####################
# Initialize kernel #
#####################

/run/initialize
/control/verbose 2
/run/verbose 2
/event/verbose 0
/tracking/verbose 1

###################
# Set proton beam #
###################
/gun/particle proton
/gun/position -150 0 0 cm
/gun/direction 1 0 0
/gun/energy 2.0 GeV
/tracking/verbose 2
/run/beamOn 1

#################################
# Tallies for energy deposition #
#################################

/score/create/cylinderMesh protonCylMesh
/score/mesh/cylinderSize 125 3 cm 
/score/mesh/nBin 1 1 1 
/score/quantity/energyDeposit boxMashkeV
/score/filter/particle protonFilt proton
/score/dumpQuantityToFile protonCylMesh boxMashkeV neuFlux.txt
/score/close

Here below the detector definition for geometry and logical volume:

  //     
  // Tungsten target of the source
  //
  G4Material* target_mat = nist->FindOrBuildMaterial("G4_W");
  G4ThreeVector pos = G4ThreeVector(0, 0, 0);

  // Trapezoid shape       
  G4double dx=125*cm, dy = 125*cm, dz=3*cm;
  G4EllipticalTube* target =    
    new G4EllipticalTube("target", dx, dy, dz); //target cylinder
                
  G4LogicalVolume* logicShape2 =                         
    new G4LogicalVolume(target,         //its solid
                        target_mat,          //its material
                        "target");           //its name
               
  new G4PVPlacement(0,                       //no rotation
                    pos,                    //at position
                    logicShape2,             //its logical volume
                    "target",                //its name
                    logicEnv,                //its mother  volume
                    false,                   //no boolean operation
                    0,                       //copy number
                    checkOverlaps);          //overlaps checking
                
  // Set Shape2 as scoring volume
  //
  fScoringVolume = logicShape2;

For the sake of completness, I provide the main:


#include "G4RunManager.hh"
#include "G4RunManagerFactory.hh"
#include "G4UImanager.hh"
#include "G4ScoringManager.hh"

#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"

#include "TargetDetectorConstruction.hh"
#include "QGSP_BERT_HP.hh"
#include "ExG4PrimaryGeneratorAction01.hh"



int main(int argc,char** argv)
{
 
  G4RunManager* runManager = new G4RunManager;
 
  G4ScoringManager::GetScoringManager();
 
  
  runManager->SetUserInitialization(new TargetDetectorConstruction);
  runManager->SetUserInitialization(new QGSP_BERT_HP);

  runManager->SetUserAction(new ExG4PrimaryGeneratorAction01);

  runManager->Initialize();

  G4VisManager* visManager = new G4VisExecutive;
  visManager->Initialize();

  G4UImanager* UImanager = G4UImanager::GetUIpointer();


  // interactive mode : define UI session
  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
  UImanager->ApplyCommand("/control/execute init_vis.mac");
  UImanager->ApplyCommand("/control/execute tallies.mac"); //macro to run the simulation and scoring
  ui->SessionStart();
  delete ui;

   // job termination
  delete runManager;
  delete visManager;
  return 0;
}

Any suggestion to fix this problem, please?
Thank you in advance for your time.
Best regards,

Christian

Hi Christian

What version of Geant4 are you using? SetUserAction has been removed for some time. You now have to put your actions in a G4VUserActionInitialization – see, for example, examples/basic/B1.

John

Dear John,

thank you very much for your answer. I have implemented the modification you suggested, considering example B1. Unfortunately, compiling without errors, the output returns a list of zeros another time.
To verify if this is a problem of my code or how I’ve used the scoring in the macro, I adopted the scoring itself for the example B1, modifying the file run1.mac and exampleB1.cc. I used a box mesh that covers the space of the geometry (/score/mesh/boxSize 160 160 160 cm) and also in this case I get zeros.
Here below run1.mac:

/score/create/boxMesh protonBoxMesh
/score/mesh/boxSize 160 160 160 cm
/score/mesh/nBin 1 1 1
/score/quantity/energyDeposit boxMashkeV
/score/filter/particle protonFilt proton
/score/dumpQuantityToFile protonBoxMesh boxMashkeV protonEne.txt
/score/close



# Macro file for example B1
# 
# Can be run in batch, without graphic
# or interactively: Idle> /control/execute run1.mac
#
# Change the default number of workers (in multi-threading mode) 
#/run/numberOfThreads 4
#
# Initialize kernel
/run/initialize
#
/control/verbose 2
/run/verbose 2
/event/verbose 0
/tracking/verbose 1
# 
# gamma 6 MeV to the direction (0.,0.,1.)
#
/gun/particle gamma
/gun/energy 6 MeV
#
/run/beamOn 5
# 
# proton 210 MeV to the direction (0.,0.,1.)
#
/gun/particle proton
/gun/energy 210 MeV
/tracking/verbose 2
#
/run/beamOn 1

the file exampleB1.cc, where I included G4ScoringManager.hh:

//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
//
//
/// \file exampleB1.cc
/// \brief Main program of the B1 example

#include "G4ScoringManager.hh"
#include "B1DetectorConstruction.hh"
#include "B1ActionInitialization.hh"

#include "G4RunManagerFactory.hh"

#include "G4UImanager.hh"
#include "QBBC.hh"

#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"

#include "Randomize.hh"

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

int main(int argc,char** argv)
{
  // Detect interactive mode (if no arguments) and define UI session
  //
  G4UIExecutive* ui = 0;
  if ( argc == 1 ) {
    ui = new G4UIExecutive(argc, argv);
  }

  // Optionally: choose a different Random engine...
  // G4Random::setTheEngine(new CLHEP::MTwistEngine);
  
  // Construct the default run manager

  auto* runManager =
    G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
  
   G4ScoringManager::GetScoringManager();


  // Set mandatory initialization classes
 
  runManager->SetUserInitialization(new B1DetectorConstruction());


  G4VModularPhysicsList* physicsList = new QBBC;
  physicsList->SetVerboseLevel(1); 
  runManager->SetUserInitialization(physicsList);
    
  runManager->SetUserInitialization(new B1ActionInitialization());
  
  // Initialize visualization
  //
  G4VisManager* visManager = new G4VisExecutive;
  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
  // G4VisManager* visManager = new G4VisExecutive("Quiet");
  visManager->Initialize();

  // Get the pointer to the User Interface manager
  G4UImanager* UImanager = G4UImanager::GetUIpointer();

  // Process macro or start UI session
  //
  if ( ! ui ) { 
    // batch mode
    G4String command = "/control/execute ";
    G4String fileName = argv[1];
    UImanager->ApplyCommand(command+fileName);
  }
  else { 
    // interactive mode
    UImanager->ApplyCommand("/control/execute init_vis.mac");
    UImanager->ApplyCommand("/control/execute run1.mac");
    ui->SessionStart();
    delete ui;
  }

  // Job termination
  // Free the store: user actions, physics_list and detector_description are
  // owned and deleted by the run manager, so they should not be deleted 
  // in the main() program !
  
  delete visManager;
  delete runManager;
}

the output protonEne.txt:

# mesh name: protonBoxMesh
# primitive scorer name: boxMashkeV
# iX, iY, iZ, total(value) [MeV], total(val^2), entry
0,0,0,0,0,0

If you have other suggestions please, thank you very much!
Best regards,

Christian

Hi Christian

I’m not familiar with command-based scoring, so can’t help you there. I see you have /tracking/verbose 2 - what does that tell you about your proton? Does it deposit energy where you think it should? Etc, etc., you’ve just got to dig around a bit.

Sorry not to be more helpful.

John

Hey Cristian,

I am also having the same problem i.e. getting zeros in the scoring. Have you found any solution.

Rohit

you might want run this single line in your macro after /run/beamOn, otherwise the empty scorer is dumped to file, and that is indeed all zeros :slight_smile:

1 Like

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