2 circular targets

@anna thank you…sorry I didn’t! Then I did it again. In attachment the new full log about all I did now.

log -DGEANT4_USE_OPENGL_WIN32=ON.txt (29.0 KB)

I also tried again to compile and run the modified B1 example and this is the log.

log B1.txt (43.3 KB)

Do you think it is ok now?

You have several warnings regarding the geometry (e.g. the overlaping volumes).
But to test the visualization you should be able to execute the example without the macro as an argument. Have a look at the README file that is distributed with every example - it explains how to run with and without the visualisation, and also check the user guide.

Hi @anna do you mean in the logB1 file?
Are they warning do to mistakes in my code or mistakes about the Geant4 installation?

Yes, in the logB1.txt. It’s coming from your application, the overlap means the placement of two volumes should be fixed to avoid potential problems with simulation:

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : GeomVol1002
      issued by : G4PVPlacement::CheckOverlaps()
Overlap with volume already placed !
          Overlap is detected for volume Envelope2:0 (G4Tubs)
          with Envelope:0 (G4Tubs) volume's
          local point (-5.45402,-0.829233,-0.929587), overlapping by at least: 570.413 um
NOTE: Reached maximum fixed number -1- of overlaps reports for this volume !
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

The other error message tells that the world volume is not a box which it should be:

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : MyCode0002
      issued by : B1PrimaryGeneratorAction::GeneratePrimaries()
Envelope volume of box shape not found.
Perhaps you have changed geometry.
The gun will be place at the center.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Thank you @anna. I guess the errors are in the B1DetectorConstruction.cc . Please, can you check it?

B1DetectorConstruction.cc (9.7 KB)

The overlap comes from missing unit (line 143), the default unit is mm in G4. Also, at the moment you place those cylinders next to each other (the shift, so the distance between the centre of both volumes, is 2mm along X-axis), I am not sure if you did not mean to have two cylinders behind each other (= along z-axis).
Regarding the other error, B1PrimaryGeneratorAction wants to deduce from Envelope volume of type G4Box where to place the particle. You changed that volume to G4Tubs. Anyway, I believe you do not need this generalisation, so you can set particle’s position directly in fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)) and remove the code above it that is no longer used.

Hi @anna, thank you. Yes, I want the two cylinders behind each other, like this picture

Then, modified the B1Detecotrconstruction.cc, by writing

 new G4PVPlacement(0,                       //no rotation
                    G4ThreeVector(0,0,2.3*cm),         //at (0,0,2.3) 2.3= 0.3*cm+2*cm
                    logicEnv2,                //its logical volume
                    "Envelope2",              //its name
                    logicWorld,              //its mother  volume
                    false,                   //no boolean operation
                    0,                       //copy number
                    checkOverlaps);          //overlaps checking

I setted the position of the second target in (0,0,2.3*cm), because 0.3cm is the thickness of the first one, and 2cm is the distance between the two targets (the 0.3+2.0=2.3). I hope this will fix the first problem.

This is the new B1Detectorconstruction.cc file

B1DetectorConstruction.cc (9.7 KB)

For the second error, I wrote


to put the particle beam 1m beafore the first target (because the first target is in 0.,0.,0).
and I commented all the code above it. I hope it will fix the second problem.

This is the new B1PrimaryGeneratorAction.cc

B1PrimaryGeneratorAction.cc (4.3 KB)

Then I compiled and runned the B1 example and this is the log

log B1.txt (96.2 KB)

I read about warnings just in this line

Visualization Manager instantiating with verbosity "warnings (3)"...

Should I fix it ?
Thank you

No, it just means what is the verbosity/what sort of messages will be printed. The errors look like those previous ones (few posts above).
Also, to see if the visualization works, execute your application without the macro:


It will execute by default init_vis.mac and from there vis.mac macros that set up how the visualisation looks - more in the application guide.

Hi @anna, thank you. I runned the B1 without the macro, but it looks like that it is impossible to open init_vis.mac

Here the log.
Thank you

logB1.txt (3.0 KB)

And do you have init_vis.mac and vis.mac in you directory where you execute the example? They should be copied by cmake from the source directory.

Hi @anna I copied the 2 files in the exe file directory. I runned the B1.exe and it opens a windows where I can see the 2 targets

The only problem is that if I click on the window where I see the picture, the windows looks like crashing (you can read NON RISPONDE that it means IT DOESN’T ANSWER)

This is the full log

logB1.txt (9.1 KB)

I believe that OpenGL creates only such a static image. But the picture looks like you achieved the geometry you intended.
To have more visualisation functionalities (e.g. rotate the image, preview the simulation etc) you need to go back to the installation of e.g. Qt. However, I am not familiar with Windows, so if you have trouble with that, please open a new thread dedicated to the installation of Geant4 with Qt on Windows.

Thank you @anna . Now I must get

  1. Input energy distribution
  2. Output energy distribution
  3. Angular energy distribution
    and to save them in ROOT files
    What should I do?

Please read the application developer’s guide and have a look at the examples.

Hi @anna thank you. I’m not sure if I understood the file which you are talking about . I think that it is this one but in the example section I just read about their features

What I meant was that you need to read more in the application developer’s guide, in particular on the analysis, you will find there explanations with the code from the examples. But have a look at those examples further (their code) to see how this was implemented.

Hi @anna thank you

my goal is to get a ROOT file like this one

in which there are NTUPLES theare stored input and output energy distributions and angular distribution, so that I can analyze them by ROOT

So, following the tutorial:

a. I created the B1Analysis.hh file

B1Analysis.hh (1.8 KB)

b. I added in the B1RunAction the code
auto analysisManager = G4Analysis::ManagerInstance(“root”);
G4cout << "Using " << analysisManager->GetType() << G4endl;



to create the Ntupla and the code

    analysisManager->CreateNtuple("B1", "Edep");
  analysisManager->CreateNtupleDColumn("Output Energy");

to create the Ntupla

B1RunAction.cc (6.5 KB)

c.I added in the B1EventAction.cc file the following code:

  analysisManager->FillNtupleDColumn(0, fEdep);

to fill the Ntupla (for the moment I just added the column about output energy).

B1EventAction.cc (2.9 KB)

but when I try to compile and run, I get errors…
here the log

Log.txt (2.8 KB)

If you use the analysis factory (available since G4 version 10.6) you do not need anymore to create the B1Analysis.hh header and instead only include g4analysis.hh.
Remember to include the same header (g4analysis.hh) in both places you use it: B1EventAction.cc and B1RunAction.cc (currently missing from the run action as indicated in the error: 'G4Analysis' non è il nome di una classe o di uno spazio dei nomi).

Next, in B1EventAction.cc you attempt to use analysisManager but do not declare it (the error that indicates it: 'analysisManager': identificatore non dichiarato). Add
auto analysisManager = G4AnalysisManager::Instance();

Hi @anna thank you.

  1. In the B1EventAction.cc
    a. I included #include "g4analysis.hh"
    b. I added in the void B1EventAction::EndOfEventAction(const G4Event*) the code
    auto analysisManager = G4AnalysisManager::Instance();

B1EventAction.cc (3.3 KB)

  1. In the B1RunAction
    a. I included #include "g4analysis.hh"
    b. In the void B1RunAction::BeginOfRunAction(const G4Run*) I added the code to open the Root File:

       auto analysisManager = G4AnalysisManager::Instance();


c. In the void B1RunAction::EndOfRunAction(const G4Run* run) I added the code to write and to close the Root file:

auto analysisManager = G4AnalysisManager::Instance();

B1EventAction.cc (3.3 KB)

  1. I compiled and running the code, and I didn’t get errors, moreover I get the B1.root file, but it’s just 1kb and it doens’t work…you can see that ROOT can’t open it

Is the file really created under C:/B1.root? The ROOT error msg suggests there should be some error at the simulation execution, can you check again the output? There is sometimes a lot of output and some messages are easy to miss…
Also, the names of the columns are best left without spaces (“Output Energy” -> “OutputEnergy”).