G4.11.3
Linux Ubuntu 24.04
gcc 3.13.0
cmake 3.28.0
I wrote some simple detector that a matrix of photocaptor to detect photon. The z position of the plane of the matrix i fixed but the numbre of rows and columns could be changed using UI command “detector” i add through UI command.
Hereafter is the main program
#include <iostream>
#include "G4RunManager.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)
{
G4RunManager *runManager = new G4RunManager();
runManager->SetUserInitialization(new MyDetectorConstruction());
runManager->SetUserInitialization(new MyPhysicsList());
runManager->SetUserInitialization(new MyActionInitialization());
runManager->Initialize();
G4UIExecutive *ui = 0;
if(argc == 1)
{
ui = new G4UIExecutive(argc,argv);
}
G4VisManager *visManager = new G4VisExecutive();
visManager->Initialize();
G4UImanager *UImanager = G4UImanager::GetUIpointer();
if(ui)
{
UImanager->ApplyCommand("/control/execute vis.mac");
ui->SessionStart();
}
else
{
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);
}
return 0;
}
and the geometry construction.hh and .cc
#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"
#include "detector.hh"
class MyDetectorConstruction : public G4VUserDetectorConstruction{
public:
MyDetectorConstruction();
~MyDetectorConstruction();
virtual G4VPhysicalVolume *Construct();
private:
G4LogicalVolume *logicDetector;
virtual void ConstructSDandField();
G4int nCols, nRows;
G4Box *solidWorld,*solidRadiator,*solidDetector;
G4LogicalVolume *logicWorld,*logicRadiator;
G4VPhysicalVolume *physWorld,*physRadiator,*physDetector;
G4GenericMessenger *fMessenger;
void DefineMaterial();
G4Material *SiO2,*H2O,*worldMat,*Aerogel;
G4Element *C;
};
#endif
#include "construction.hh"
MyDetectorConstruction::MyDetectorConstruction()
{
fMessenger = new G4GenericMessenger(this, "/detector/", "Detector Construction");
fMessenger->DeclareProperty("nCols",nCols, "Number of columns");
fMessenger->DeclareProperty("nRows",nRows, "Number of rows");
nCols = 100;
nRows = 100;
DefineMaterial();
}
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);
}
G4VPhysicalVolume *MyDetectorConstruction::Construct()
{
G4double xWorld = 0.5*m;
G4double yWorld = 0.5*m;
G4double zWorld = 0.5*m;
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);
solidRadiator = new G4Box("solidRadiator", 0.4*m, 0.4*m, 0.01*m);
logicRadiator = new G4LogicalVolume(solidRadiator,Aerogel,"logicalRadiator");
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");
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;
}
}
return physWorld;
}
void MyDetectorConstruction::ConstructSDandField()
{
MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector");
logicDetector->SetSensitiveDetector(sensDet);
}
I fixed to 100 the initial number of columns and rows. The compilation and execution is OK
i try to change the number of rows abnd columns from 100x100 to 10x10 using the commands
/detector/nCols 10
/detector/nRows 10
/run/reinitializeGeometry
I check using some G4cout in the construct method that the geometry is redefined…but when i run some event i still have the initial geometry with 100x100 matrix
if some expert can help me !!