How to modify a geometry using messengers in interactive mode

_Geant4 Version: V11.2.2
_Operating System Ubuntu 24.04 LTS

I would like to modify the geometry of my detector using commands in interactive mode. These commands are defined by messengers.

The modifications are:

  1. either to change the number of rows or columns in a detector matrix
  2. or to choose between two types of sub-detectors

In the first case, I defined two commands in the constructor to define two variables (double): nCols and nRows

In the second case, I defined two commands to define two Boolean variables to initiate the construction of one or two options: isCherenkov (false by default), isScintillator (false by default).

When I use these commands, the variable changes are correctly taken into account in the code.

However, I can’t visualize the geometry after the commands.

Once the geometry of the detector is modified using messengers commands as

/detector/Cherenkov true

/detector/nRow 20

i run the following sequence of commands,

/run/reinitialyseGeometry
/run/initialize

but nothing happens…

i try also following sequences

/run/reinitialyseGeometry
/vis/scene/notifyHandler
/run/initialize

Hereafter the main

#include <iostream>

#include "G4RunManager.hh"
#include "G4MTRunManager.hh"
#include "G4UImanager.hh"
#include "G4VisManager.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"

#include "construction.hh"
#include "physics.hh"
#include "action.hh"

int main(int argc, char** argv)
{

    G4UIExecutive *ui = 0;

    #ifdef G4MULTITHREADED
      G4MTRunManager *runManager = new G4MTRunManager();
    #else
      G4RunManager *runManager = new G4RunManager();
    #endif

    runManager->SetUserInitialization(new MyDetectorConstruction());
    runManager->SetUserInitialization(new MyPhysicsList());
    runManager->SetUserInitialization(new MyActionInitialization());

    G4cout << "argc = " <<  argc <<  G4endl;


    if(argc == 1)
    {
        ui = new G4UIExecutive(argc,argv);
        G4cout << "path #1" <<  G4endl;
    }

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

    G4UImanager *UImanager = G4UImanager::GetUIpointer();

    if(ui)
    {
        G4cout << "path #2" <<  G4endl;
        UImanager->ApplyCommand("/control/execute vis.mac");
        ui->SessionStart();

    }
    else
    {
        G4cout << "path #2" <<  G4endl;
        G4String command = "/control/execute ";
        G4String fileName = argv[1];
        UImanager->ApplyCommand(command+fileName);

    }

    return 0;
}

the detector construction

#include "construction.hh"

MyDetectorConstruction::MyDetectorConstruction()
{

        nCols = 10;
        nRows = 10;

        fMessenger = new G4GenericMessenger(this, "/detector/", "Detector Construction");

        fMessenger->DeclareProperty("nCols",nCols, "Number of columns");
        fMessenger->DeclareProperty("nRows",nRows, "Number of rows");
        fMessenger->DeclareProperty("Cherenkov",isCherenkov, "Toogle Cherenkov Setup");
        fMessenger->DeclareProperty("Scintillator",isScintillator, "Toogle Scintillator Setup");

        DefineMaterial();

        xWorld = 0.5*m;
        yWorld = 0.5*m;
        zWorld = 0.5*m;

        isCherenkov = false;
        isScintillator = false;
}

MyDetectorConstruction::~MyDetectorConstruction()
{}

void MyDetectorConstruction::DefineMaterial()
{
        G4NistManager *nist = G4NistManager::Instance();

        SiO2 = new G4Material("SiO2", 2.201*g/cm3, 2);
        SiO2->AddElement(nist->FindOrBuildElement("Si"),1);
        SiO2->AddElement(nist->FindOrBuildElement("O"),2);

        H2O = new G4Material("H2O", 1.0000*g/cm3, 2);
        H2O->AddElement(nist->FindOrBuildElement("H"),2);
        H2O->AddElement(nist->FindOrBuildElement("O"),1);

        C = nist->FindOrBuildElement("C");

        Aerogel = new G4Material("Aerogel", 0.200*g/cm3, 3);
        Aerogel->AddMaterial(SiO2, 62.5*perCent);
        Aerogel->AddMaterial(H2O, 37.4*perCent);
        Aerogel->AddElement(C, 0.1*perCent);

        worldMat = nist ->FindOrBuildMaterial("G4_AIR");

        G4double energy[2] {1.239841939*eV/0.9, 1.239841939*eV/0.2};
        G4double rindexAerogel[2] {1.1, 1.1};
        G4double rindexWorld[2] {1.0, 1.0};

        G4MaterialPropertiesTable *mptAerogel = new G4MaterialPropertiesTable();
        mptAerogel->AddProperty("RINDEX", energy, rindexAerogel, 2);

        G4MaterialPropertiesTable *mptWorld = new G4MaterialPropertiesTable();
        mptWorld->AddProperty("RINDEX", energy, rindexWorld, 2);

        Aerogel->SetMaterialPropertiesTable(mptAerogel);

        worldMat->SetMaterialPropertiesTable(mptWorld);
}


void MyDetectorConstruction::ConstructCherenkov()
{
        solidRadiator = new G4Box("solidRadiator", 0.4*m, 0.4*m, 0.01*m);
        logicRadiator = new G4LogicalVolume(solidRadiator,Aerogel,"logicalRadiator");

        fScoringVolume = logicRadiator;

        physRadiator = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.25*m), logicRadiator, "physRadiator", logicWorld, false, 0, true);

        solidDetector = new G4Box("solidDetector", xWorld/nRows, yWorld/nCols, 0.01*m);

        logicDetector = new G4LogicalVolume(solidDetector, worldMat, "logicDetector");

        G4cout<<"nCols"<<nCols<<"nRows" <<nRows<< G4endl;

        for(G4int i = 0; i < nRows; i++)
        {
                for(G4int j = 0; j < nCols; j++)
                {
                        physDetector = new G4PVPlacement(0,G4ThreeVector(-0.5*m+(i+0.5)*m/nRows,
                                                                         -0.5*m+(j+0.5)*m/nCols, 0.49*m),
                                                         logicDetector, "physDetector", logicWorld, false,
                                                         j+i*nCols, true);

                        G4double xx =-0.5*m+(i+0.5)*m/nRows;
                        G4double yy =-0.5*m+(j+0.5)*m/nCols;
                        G4double zz =0.49*m;




                        G4cout << "Capteur " << " i = " << i << " j = " << j << "  Capteur Position : " << " x =" << xx << " y = " << yy << " z = " << zz << G4endl;
                }
        }
}

G4VPhysicalVolume *MyDetectorConstruction::Construct()
{
        solidWorld = new G4Box("solidWorld", xWorld, yWorld, zWorld);
        logicWorld = new G4LogicalVolume(solidWorld, worldMat, "logicWorld");
        physWorld = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), logicWorld, "physWord", 0, false, 0, true);

        G4cout << "Construction Cherenkov 1" << G4endl;

        if(isCherenkov)
        {
                ConstructCherenkov();
                G4cout << "Construction Cherenkov 2" << G4endl;
        }



        return physWorld;
}

void MyDetectorConstruction::ConstructSDandField()
{

        MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector");
        if(isCherenkov)
                logicDetector->SetSensitiveDetector(sensDet);

        G4cout << "isCherenkov " <<  isCherenkov <<  G4endl;
}

the definition of the sensitive volume

#include "detector.hh"

MySensitiveDetector::MySensitiveDetector(G4String name) :
G4VSensitiveDetector(name)
{
    quEff = new G4PhysicsOrderedFreeVector();

    std::ifstream datafile;
    datafile.open("eff.dat");

    while(1)
    {
        G4double wlen, queff;
        datafile >> wlen >> queff;

        if(datafile.eof())
            break;

        G4cout << wlen << " " << queff << G4endl;
        quEff->InsertValues(wlen, queff/100.);
    }

    datafile.close();

    //quEff->SetSpline(false);

}

MySensitiveDetector::~MySensitiveDetector()
{}

G4bool MySensitiveDetector::ProcessHits(G4Step *aStep,
                                G4TouchableHistory *ROhist)
{
    G4Track *track = aStep->GetTrack();


    track->SetTrackStatus(fStopAndKill);

    G4StepPoint *preStepPoint  = aStep->GetPreStepPoint();
    G4StepPoint *postStepPoint = aStep->GetPostStepPoint();

    G4ThreeVector posPhoton = preStepPoint->GetPosition();
    G4ThreeVector momPhoton = preStepPoint->GetMomentum();

    G4double wlen = (1.239841939*eV/momPhoton.mag())*1E+03;

    //G4cout << "Photon position: " << posPhoton << G4endl;

    const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();

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

    G4VPhysicalVolume *physVol = touchable->GetVolume();
    G4ThreeVector posDetector = physVol->GetTranslation();

    //#ifndef G4MULTITHREATED
    //G4cout << "Detector position: " << posDetector << G4endl;
    //#endif


    G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();

    G4cout << "Event Number: " << evt << G4endl;


    G4AnalysisManager *man = G4AnalysisManager::Instance();

    man->FillNtupleIColumn(0,0,evt);
    man->FillNtupleDColumn(0,1,posPhoton[0]);
    man->FillNtupleDColumn(0,2,posPhoton[1]);
    man->FillNtupleDColumn(0,3,posPhoton[2]);
    man->FillNtupleDColumn(0,4,wlen);
    man->AddNtupleRow(0);

    if(G4UniformRand() < quEff->Value(wlen))
    {
        man->FillNtupleIColumn(1,0,evt);
        man->FillNtupleDColumn(1,1,posDetector[0]);
        man->FillNtupleDColumn(1,2,posDetector[1]);
        man->FillNtupleDColumn(1,3,posDetector[2]);
        man->AddNtupleRow(1);
    }


    return true;
}

the macro to initialize the visualization

/run/initialize
/vis/open OGL
/vis/viewer/set/viewpointVector 1 1 1
/vis/drawVolume
/vis/viewer/set/autoRefresh false
/vis/scene/add/trajectories smooth
/vis/scene/add/scale 10 cm
/vis/scene/add/axes
/vis/scene/add/eventID
#/vis/scene/endOfEventAction accumulate

Where is the bug ? How can we redraw the modified geometry ?


I think the command is

/run/reinitializeGeometry

Does that help?

I do use the correct command since i use the predfined command..

I deeply insight in the forum and found that same problem appear from time to time

the most recent one use same type of code as me

but never been solved…

i am wondering if it is possible to redraw a geometry even it had been changed or not ..

It should be possible. I don’t know where the problem resides; it might be a vis issue, it might not. I am happy to look into this on the vis side if someone can send me an example app (simplified as much as possible). I have asked before. Can you send me the source code of something that runs “out of the box” if I follow Geant4 standard build procedures?

Dear @montarou

Thank you for your post.

The feature you are looking for is explained step by step in the Geant4 beginners course [1]. Recordings of the 2024 are available in CDS, and the code in github (links are found in each time slot of the indico event)

Best,
Alvaro

[1] First steps with Geant4 (15-19 April 2024): Timetable · Indico

Dear Alvaro

Thank’s a lot for this information. I will look at this carefully
gerard

Hi Gerard

This issue seems to arise a lot. If you find a solution, either from Alvaro’s advice or anywhere, please post it here.

Also, we may be able to improve the documentation, Dynamic Geometry Setups — Book For Application Developers 11.3 documentation. Is it, perhaps, not adequate? Let us know.

Good luck
John

Following this post hereafter my contribution.

This simple example is intended to test modifying geometry with interactive commands and messengers.
The geometry consists of a World volume within which a cubic-shaped volume (MiniX) is positioned,
Dimensions of the volume MiniX (fsizeXY and fsizeZ) can be modified using interactive commands.

These commands are defined by an instance of the MyDetectorMessenger user class.

Once the executable (sim1) is created, run it without any arguments.
The program runs in interactive mode.

The init_vis.mac macro is run to initialize the interactif graphics frame.
This macro finally executes the vis.mac macro.

sim.cc is the main program

#include <iostream>

#include "G4RunManager.hh"
#include "G4MTRunManager.hh"

#include "G4RunManagerFactory.hh"

#include "G4UImanager.hh"
#include "G4UIExecutive.hh"

#include "G4VisManager.hh"
#include "G4VisExecutive.hh"


#include "construction.hh"
#include "physics.hh"
#include "action.hh"

#include "G4RunManagerFactory.hh"

int main(int argc, char** argv)
{

    G4String macrofile = "";
    G4UIExecutive* ui  = nullptr;
    if ( argc == 1 ) {     // cas pas de macro file
     ui = new G4UIExecutive(argc, argv);
    } else {
     macrofile = argv[1]; // cas macrofile
    }

    #ifdef G4MULTITHREADED
      G4MTRunManager *runManager = new G4MTRunManager();
    #else
      auto* runManager  = G4RunManagerFactory::CreateRunManager();
      //G4RunManager *runManager = new G4RunManager();
    #endif

    runManager->SetUserInitialization(new MyDetectorConstruction());
    runManager->SetUserInitialization(new MyPhysicsList());
    runManager->SetUserInitialization(new MyActionInitialization());

    // set up visualisation
    G4VisManager* visManager = new G4VisExecutive;
    visManager->Initialize();

    G4UImanager* UImanager = G4UImanager::GetUIpointer();
    if ( ui == nullptr) {
      // macro file: execute
      G4String cmd = "/control/execute ";
      UImanager->ApplyCommand(cmd + macrofile);
    } else {
      // interactive: start session
      UImanager->ApplyCommand("/control/execute init_vis.mac");
      ui->SessionStart();
      delete ui;
    }

    return 0;
}

Geometry is defined by the MyDetectorConstruction class (construction.hh and .cc files)

#ifndef CONSTRUCTION_HH
#define CONSTRUCTION_HH

#include "G4VUserDetectorConstruction.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4PVPlacement.hh"
#include "G4NistManager.hh"
#include "G4SystemOfUnits.hh"

#include "G4GenericMessenger.hh"

class MyDetectorMessenger;

class MyDetectorConstruction : public G4VUserDetectorConstruction{
    public:
        MyDetectorConstruction();
        ~MyDetectorConstruction();

        virtual G4VPhysicalVolume *Construct();

        void    SetMiniX_XY(const G4double sizeXY );
        G4double GetMiniX_XY() const { return fsizeXY; }

        void    SetMiniX_Z(const G4double sizeZ );
        G4double GetMiniX_Z() const { return fsizeZ; }

    private:
        G4Box *solidWorld;
        G4LogicalVolume *logicWorld,*logicMiniX;
        G4VPhysicalVolume *physWorld,*physMiniX;

        G4Material *H2O,*worldMat;

        void DefineMaterial();
        virtual void ConstructSDandField();

        MyDetectorMessenger *fMessenger;

        // MiniX dimensions
        G4double fsizeXY, fsizeZ;

        G4double xWorld, yWorld, zWorld;
};
#endif


#include "construction.hh"

#include "G4NistManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4RunManager.hh"

#include "messenger.hh"

MyDetectorConstruction::MyDetectorConstruction()
{
        fsizeXY =  50*cm;
        fsizeZ  =  50*cm;

        G4cout << "valeurs initiales" << "sizeXY : "<<fsizeXY<<"sizeZ : " <<fsizeZ << G4endl;

        fMessenger = new MyDetectorMessenger(this);

        DefineMaterial();

        xWorld = 1.5*m;
        yWorld = 1.5*m;
        zWorld = 1.5*m;

        G4cout << "valeurs initiales" << "xWorld : "<< xWorld <<"yWorld : " << yWorld << "zWorld : "<< zWorld  <<  G4endl;
}

MyDetectorConstruction::~MyDetectorConstruction()
{
       delete fMessenger ;
}

void MyDetectorConstruction::SetMiniX_XY(const G4double sizeXY ){
       fsizeXY = sizeXY;
       G4RunManager::GetRunManager()->ReinitializeGeometry();
}

void MyDetectorConstruction::SetMiniX_Z(const G4double sizeZ ){
       fsizeZ   = sizeZ;
       G4RunManager::GetRunManager()->ReinitializeGeometry();
}


void MyDetectorConstruction::DefineMaterial()
{
        G4NistManager *nist = G4NistManager::Instance();

        H2O = new G4Material("H2O", 1.0000*g/cm3, 2);
        H2O->AddElement(nist->FindOrBuildElement("H"),2);
        H2O->AddElement(nist->FindOrBuildElement("O"),1);

        worldMat = nist ->FindOrBuildMaterial("G4_AIR");
}

G4VPhysicalVolume *MyDetectorConstruction::Construct()
{
        // Option to switch on/off checking of volumes overlaps
        G4bool checkOverlaps = true;

        auto solidWorld = new G4Box("solidWorld",xWorld,yWorld,zWorld);

        auto logicWorld = new G4LogicalVolume(solidWorld,worldMat,"logicWorld");

        auto physWorld = new G4PVPlacement(nullptr,G4ThreeVector(0.,0.,0.),logicWorld,"physWord",
                                           0,false,0, checkOverlaps);
        // Box MiniX

        G4ThreeVector posMiniX = G4ThreeVector(0,0,-5*cm);

         G4cout << "dans construct " << "fsizeXY : " << fsizeXY << "fsizeZ : " << fsizeZ << G4endl;

        G4double MiniX_sizeXY= fsizeXY;
        G4double MiniX_sizeZ = fsizeZ;

        G4cout << "MiniX_sizeXY : "<<MiniX_sizeXY<<"MiniX_sizeZ : " <<MiniX_sizeZ << G4endl;

        auto solidMiniX = new G4Box("MiniX",MiniX_sizeXY,MiniX_sizeXY,MiniX_sizeZ);

        auto logicMiniX = new G4LogicalVolume(solidMiniX,worldMat,"MiniX");

        auto physMiniX  = new G4PVPlacement(nullptr,posMiniX,logicMiniX,"MiniX",logicWorld,false,0,checkOverlaps);

        return physWorld;
}

void MyDetectorConstruction::ConstructSDandField(){}


Messengers are defined by the MyDetectorMessenger class (messenger.hh and .cc files)

#include "G4UImessenger.hh"

class MyDetectorConstruction;

class G4UIdirectory;
class G4UIcmdWithADoubleAndUnit;


class MyDetectorMessenger : public G4UImessenger {

public:
    MyDetectorMessenger(MyDetectorConstruction *det);
    ~ MyDetectorMessenger() override;

    void SetNewValue(G4UIcommand*,G4String par) override;

private:
    MyDetectorConstruction* fMyDetector;

    G4UIdirectory* fDirCmd;
    G4UIcmdWithADoubleAndUnit* fMiniX_XYcmd;
    G4UIcmdWithADoubleAndUnit* fMiniX_Zcmd;
};

#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIdirectory.hh"

#include "construction.hh"
#include "messenger.hh"

MyDetectorMessenger::MyDetectorMessenger(MyDetectorConstruction *det)
    : G4UImessenger(),
      fMyDetector(det) {

      fDirCmd = new G4UIdirectory("/sim1/det/");
      fDirCmd->SetGuidance("Change Geometry of Detector...");

      fMiniX_XYcmd = new G4UIcmdWithADoubleAndUnit("/sim1/det/setMiniXSizeXY",this);
      fMiniX_XYcmd->SetGuidance("Set The XY of the MiniX");
      fMiniX_XYcmd->SetUnitCategory("Length");
      fMiniX_XYcmd->AvailableForStates(G4State_PreInit,G4State_Idle);

      fMiniX_Zcmd = new G4UIcmdWithADoubleAndUnit("/sim1/det/setMiniXSizeZ",this);
      fMiniX_Zcmd->SetGuidance("Set The Z of the MiniX");
      fMiniX_Zcmd->SetUnitCategory("Length");
      fMiniX_Zcmd->AvailableForStates(G4State_PreInit,G4State_Idle);

      }

MyDetectorMessenger::~MyDetectorMessenger(){
      delete fDirCmd;
      delete fnRowscmd;
      delete fnColscmd;
}

void MyDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) {

    if( command == fMiniX_XYcmd ) {
        G4double Mini_XY = fMiniX_XYcmd->GetNewDoubleValue(newValue);
        fMyDetector->SetMiniX_XY(Mini_XY);
    }
    if( command == fMiniX_Zcmd ) {
        G4double Mini_Z =fMiniX_Zcmd->GetNewDoubleValue(newValue);
        fMyDetector->SetMiniX_Z(Mini_Z);
    }

}


Physics (decay of a CO60 source) is defined by the MyPhysicsList class (physics.hh and .cc files)

#ifndef PHYSICS_HH
#define PHYSICS_HH

#include "G4VModularPhysicsList.hh"
#include "G4EmStandardPhysics.hh"
#include "G4OpticalPhysics.hh"
#include "G4DecayPhysics.hh"
#include "G4RadioactiveDecayPhysics.hh"

class MyPhysicsList : public G4VModularPhysicsList
{
public:
    MyPhysicsList();
    ~MyPhysicsList();
};

#endif

#include "physics.hh"

MyPhysicsList::MyPhysicsList()
{
    RegisterPhysics (new G4EmStandardPhysics());
    RegisterPhysics (new G4DecayPhysics());
    RegisterPhysics (new G4RadioactiveDecayPhysics());
}

MyPhysicsList::~MyPhysicsList(){}


Primary events are defined by the MyPrimaryGenerator class (generator.hh and cc files)

#ifndef GENERATOR_HH
#define GENERATOR_HH

#include "G4VUserPrimaryGeneratorAction.hh"

#include "G4ParticleGun.hh"
#include "G4SystemOfUnits.hh"
#include "G4ParticleTable.hh"
#include "G4Geantino.hh"
#include "G4IonTable.hh"

class MyPrimaryGenerator : public G4VUserPrimaryGeneratorAction
{
public:
    MyPrimaryGenerator();
    ~MyPrimaryGenerator();

    virtual void GeneratePrimaries(G4Event*);

private:
    G4ParticleGun *fParticleGun;
};

#endif

#include "generator.hh"

MyPrimaryGenerator::MyPrimaryGenerator()
{
    fParticleGun = new G4ParticleGun(1);

    G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
    G4ParticleDefinition *particle = particleTable->FindParticle("geantino");

    G4ThreeVector pos(0.,0.,0.);
    G4ThreeVector mom(0.,0.,1.);

    fParticleGun->SetParticlePosition(pos);
    fParticleGun->SetParticleMomentumDirection(mom);
    fParticleGun->SetParticleMomentum(0.*GeV);
    fParticleGun->SetParticleDefinition(particle);
}

MyPrimaryGenerator::~MyPrimaryGenerator()
{
    delete fParticleGun;
}

void MyPrimaryGenerator::GeneratePrimaries(G4Event *anEvent)
{
    G4ParticleDefinition *particle = fParticleGun->GetParticleDefinition();

    if(particle == G4Geantino::Geantino())
    {
        G4int Z = 27;
        G4int A = 60;

        G4double charge = 0.*eplus;
        G4double energy = 0.*keV;

        G4ParticleDefinition *ion = G4IonTable::GetIonTable()->GetIon(Z,A,energy);

        fParticleGun -> SetParticleDefinition(ion);
        fParticleGun -> SetParticleCharge(charge);
    }
    fParticleGun->GeneratePrimaryVertex(anEvent);
}


The action.hh and .cc files define the MyActionInitialization class

#ifndef ACTION_HH
#define ACTION_HH

#include "G4VUserActionInitialization.hh"
#include "generator.hh"

class MyActionInitialization : public G4VUserActionInitialization
{
public:
        MyActionInitialization();
        ~MyActionInitialization();

        virtual void Build() const;
        virtual void BuildForMaster() const;
};

#endif


#include "action.hh"

MyActionInitialization::MyActionInitialization()
{}

MyActionInitialization::~MyActionInitialization()
{}

void MyActionInitialization::BuildForMaster() const
{}

void MyActionInitialization::Build() const
{
    MyPrimaryGenerator *generator = new MyPrimaryGenerator();
    SetUserAction(generator);
}



The MyDetectorConstruction, MyPhysicsList, and MyActionInitialization actions are declared to an instance of the runManager in the main program

The init_vis.mac and vis.mac macros are used to define the graphical framework in interactive mode

# Macro file for the initialization of example B1
# in interactive session
#
# Set some default verbose
/control/verbose 2
/control/saveHistory
/run/verbose 2
#
# Change the default number of threads (in multi-threaded mode)
#/run/numberOfThreads 4
#
# Initialize kernel
/run/initialize
#
# Visualization setting
/control/execute vis.mac


/vis/open OGL
/run/initialize
/vis/viewer/set/viewpointVector 1 1 1
/vis/drawVolume
#/vis/viewer/set/autoRefresh false
/vis/scene/add/trajectories smooth
/vis/scene/add/scale 10 cm
/vis/scene/add/axes
/vis/scene/add/eventID
#/vis/scene/endOfEventAction accumulate


When running in graphical mode, you can use the commands predefined by messenger to modify the volume MiniX dimensions:

Once the modification is complete, you must use the following commands:

/run/initialize
/vis/Drawvolume

I was unable to successfully use the command /run/reinitializeGeometry

Sorry, Gerard. Could you zip or tar your files and attach the resulting file? It’s very tedious to copy and paste them from your “in message” code. If you can do that, I’ll give it a try.

John

action.cc (324 Bytes)
action.hh (342 Bytes)
construction.cc (2.5 KB)
construction.hh (1.1 KB)
generator.cc (1.1 KB)
generator.hh (455 Bytes)
messenger.cc (1.4 KB)
messenger.hh (499 Bytes)
physics.cc (241 Bytes)
physics.hh (325 Bytes)

sim.cc (1.5 KB)

# Macro file for the initialization of example B1
# in interactive session
#
# Set some default verbose
/control/verbose 2
/control/saveHistory
/run/verbose 2
#
# Change the default number of threads (in multi-threaded mode)
#/run/numberOfThreads 4
#
# Initialize kernel
/run/initialize
#
# Visualization setting
/control/execute vis.mac

Sorry again, Gerard. Are you not familiar with zip (gzip) or tar?

For anyone following this thread, to send an app to us for diagnosing, it’s much easier if you can collect and test an app in a working directory, then zip or gzip or tar the directory into one file. I’m not so familiar with (g)zip, but I see you’re on Ubuntu, Gerard, so you must have access to the Unix “tape archive” application, tar. man tar to see the manual. To make a compressed tar file, change to the directory one above the app directory. Then

tar czf myApp.tgz myApp

where myAapp is the name of the directory (whatever), and attach myApp.tgz. On my side, all I have to do is download one file, myApp.tgz, and “untar” it.

Geant4 developers are very willing to help, but we do need users to do some work to make it simpler for us. I appreciate your willingness, Gerard, to make a simple app for us to diagnose.

(This assumes the G4 Forum will accept tgz files. I haven’t tried. If it doesn’t, please email it to john.allison@cern.ch, with the file as an attachment.)

We’re getting there.

Note: the files should include your CMakeLists.txt file too.

John

Hi Gerard

Thanks for sending the zip file by email. It has helped me find the problem and suggest a solution. I have replied in detail by email.

I refer to Run — Book For Application Developers 11.3 documentation, which refers to two cases:

  • delete the entire structure of your old geometry and build up a completely new set of volumes.
  • a “minor change” to a geometry component, which can be done “in place”.

It turned out that you were changing a parameter of your detector construction, then

G4RunManager::GetRunManager()->ReinitializeGeometry();

But ReinitializeGeometry() (without argument) does not invoke your detector construction Construct() method; it is intended for “minor changes”. To use this way, you have to change the actual geometry components with Set methods, e.g., solidMiniX->SetXHalfLength(sizeXY), not just the parameters of the detector construction (which do nothing until Construct() is called). This fixes it for me.

If you want to destroy your geometry and reconstruct it, you can add an argument: ReinitializeGeometry(true). It will destroy the existing geometry, and the vis manager will remove the geometry model. Then it seems you have to /run/initialize and /vis/scene/add/volume to re-establish the geometry and the view.

Hope that helps.

John

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