Problem in For loop "/run/beam On xxx" in main.cc

Hi,

I’m trying to make a loop in the main file like this:

G4UImanager* UImanager = G4UImanager::GetUIpointer();

G4TScoreNtupleWriter<G4AnalysisManager> scoreNtupleWriter;
  scoreNtupleWriter.SetVerboseLevel(1);
  
  if ( ! ui ) {
    // batch mode
    UImanager->ApplyCommand("/control/execute init_vis.mac");
    for (lambda_fotone = 250; lambda_fotone < 251; lambda_fotone++){

          G4cout << "######################################" << G4endl;
          G4cout << "# È in corso il run a " << 1240/lambda_fotone << " eV a " << lambda_fotone << " nm." << G4endl;
          G4cout << "######################################" << G4endl;
          UImanager->ApplyCommand("/gun/energy 1240/i eV");
          UImanager->ApplyCommand("/run/beamOn 1000000");
          

        }
  }

where the global definition of lambda_fotone is inside the DetectorConstruction.hh class:

class DetectorConstruction : public G4VUserDetectorConstruction
{
  public:
    DetectorConstruction();
    ~DetectorConstruction() override;

    G4int lambda_fotone = 250; //Wavelengh in nm 
    G4double Energia_fotone = 1240/lambda_fotone; //Energy in eV

  public:
    G4VPhysicalVolume* Construct() override;
    void ConstructSDandField() override;

  private:
    void DefineMaterials();

Then, the variable lambda_fotone is also called in the source file DetectorConstruction.cc in order to set reflectivity and transmission that depend on that parameter:

if ( lambda_fotone >= 250 && lambda_fotone < 260 ) { /*see Dicken - Accelerated UV weathering device based on integrating sphere technology*/

  std::vector<G4double> reflectivity = {0.955};
  std::vector<G4double> trasmittance = {0.045};
  std::vector<G4double> rindex_teflon = {1.30};
  std::vector<G4double> absorption = {1*um};           //il dato è errato, ma ai fini della simulazione non interessa


  TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
  TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
  TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
  TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);
  
  G4cout << "************************************************************************************" << G4endl;
  G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
                                           " [u.a] Absorption Lenght " << absorption[0] <<
                                           " [c.m.] Reflectivity " << reflectivity[0] <<
                                           " [u.a.] Trasmittance " << trasmittance[0] << G4endl;
  G4cout << "************************************************************************************" << G4endl;  

      } else if ( lambda_fotone >= 260 && lambda_fotone < 270 ) {

        std::vector<G4double> reflectivity = {0.965};
        std::vector<G4double> trasmittance = {0.035};
        std::vector<G4double> rindex_teflon = {1.30};
        std::vector<G4double> absorption = {1*um};     //il dato è errato, ma ai fini della simulazione non interessa


        TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
        TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
        TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
        TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);

        G4cout << "************************************************************************************" << G4endl;
        G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
                                           " [u.a] Absorption Lenght " << absorption[0] <<
                                           " [c.m.] Reflectivity " << reflectivity[0] <<
                                           " [u.a.] Trasmittance " << trasmittance[0] << G4endl;
        G4cout << "************************************************************************************" << G4endl; 

          } else if ( lambda_fotone >= 270 && lambda_fotone < 280 ) {

            std::vector<G4double> reflectivity = {0.975};
            std::vector<G4double> trasmittance = {0.025};
            std::vector<G4double> rindex_teflon = {1.30};
            std::vector<G4double> absorption = {1*um}; //il dato è errato, ma ai fini della simulazione non interessa


            TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
            TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
            TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
            TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);

            G4cout << "************************************************************************************" << G4endl;
            G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
                                           " [u.a] Absorption Lenght " << absorption[0] <<
                                           " [c.m.] Reflectivity " << reflectivity[0] <<
                                           " [u.a.] Trasmittance " << trasmittance[0] << G4endl;
            G4cout << "************************************************************************************" << G4endl; 

            }   else if ( lambda_fotone >= 280 && lambda_fotone < 290 ) {

                std::vector<G4double> reflectivity = {0.985};
                std::vector<G4double> trasmittance = {0.025};
                std::vector<G4double> rindex_teflon = {1.30};
                std::vector<G4double> absorption = {1*um}; //il dato è errato, ma ai fini della simulazione non interessa


                TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
                TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
                TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
                TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);

                G4cout << "************************************************************************************" << G4endl;
                G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
                                           " [u.a] Absorption Lenght " << absorption[0] <<
                                           " [c.m.] Reflectivity " << reflectivity[0] <<
                                           " [u.a.] Trasmittance " << trasmittance[0] << G4endl;
                G4cout << "************************************************************************************" << G4endl; 

                }   else { 

                    std::vector<G4double> reflectivity = {0.99}; 
                    std::vector<G4double> trasmittance = {0.01}; //se vuoi vedere la geometria della sorgente metti a 1
                    std::vector<G4double> rindex_teflon = {1.30};
                    std::vector<G4double> absorption = {1*um};   //il dato è errato, ma ai fini della simulazione non interessa

                    TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
                    TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
                    TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
                    TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);

                    G4cout << "************************************************************************************" << G4endl;
                    G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
                                           " [u.a] Absorption Lenght " << absorption[0] <<
                                           " [c.m.] Reflectivity " << reflectivity[0] <<
                                           " [u.a.] Trasmittance " << trasmittance[0] << G4endl;
                    G4cout << "************************************************************************************" << G4endl; 

  }

Running the simulation i saw two problems:

  1. The value of lamba_fotone setted in main loop is overwritten to the value setted in the DetectorConstruction.hh;
  2. The energy setted in main loop is casted to an int. This creates major errors in setting the correct reflection and transmission values and fixing the energy of the emitted particles.

My goal is to execute n run with n different energy.
why do I get these errors?

I also think that the command

UImanager->ApplyCommand("/gun/energy 1240/i eV");

does not understand math operation :confused:

HI Samuele

Gosh, it looks a complicated way to achieve your purposes!

Anyway, let’'s look.

lambda_fotone is not global (as fas as I can see) because it’s inside the class definition of DetectorConstruction. So in your main program:

what is lambda_fotone? To access the one in DetectorConstruction you would have to use something like:

  myDetectorConstruction->lambda_fotone

where

  auto myDetectorConstruction = new DetectorConstruction;

somewhere prior to that.

Also,

is very strange. Wavlength is a real quantity, so should be double (or G4double).

Also…!!! You should use the Geant4 units system:

    G4double lambda_fotone = 250*nm;

(requires #include "G4SystemOfUnits").

Finally, if you want to make several runs of different energies, why not simply make several jobs of different energies? Why do you want to put them all in one big job? If. you really want to do that, why not write a long run.mac that says something like:

/gun/energy 10 eV
/run/beamOn 1000000
/gun/energy 20 eV
/run/beamOn 1000000
...

Well, that’s my contribution. It’s still looks overly complicated to me.

John

1 Like

First of all, thanks for your contribution.

  1. lambda_fotone is the wavelenght in nm of the photon that i shoot. I need it to be a global variable because i want to change it, in the main file, from 250 nm to 350 nm, in order to make 50 runs;

  2. Why if I use G4double lambda_fotone = 250*nm and I print it I get 0.0025? I don’t understand.

  3. Your suggestion it is very good and works, but for every run i need to know wich is the energy because i need to set the right value of Reflectivity and ```Transmission`` as I said previusly:

what do you think of these statements?

Hi Samuele

Oh, so lambda_fotone is global? If it’s global it’s not the same lambda_fotone as the one described in DetectorConstruction.

When you print, you need to choose your unit:

  G4cout << lambda_fotone/nm << "nm" << G4endl;

lambda_fotone = 250*nm converts it to G4 internal units and lambda_fotone/nm converts it back again. That’s how it works. (You don’t need to know what the internal unit is, but, in the case of length, it’s millimetres, so that explains your output.)

So…pick up the energy from the particle gun. I think that should work. In your detector construction, something like:

  auto energy = myPrimaryGenerator->GetParticleGun()->GetEnergy();

Hope this helps.
John

To get your primary generator in your detector construction you could write something like:

  auto runManager = G4RunManager::GetRunManager();
  auto myPrimaryGenerator = static_cast<MyPrimaryGenerator*>(runManager->GetPrimaryGenerator());

(You would have to #include "G4RunManager.hh" and #include "MyPrimaryGenerator.hh" (or whatever you call it).)

  1. What do you mean with:

?

  1. Ok, now I understand.

Where can I read the internal unity?

  1. That’s was my original idea, but I not was able to implement it. I tryed to follow your advice:
#include "PrimaryGeneratorAction.hh"
#include "G4RunManager.hh"

  auto runManager = G4RunManager::GetRunManager();
  auto myPrimaryGenerator = static_cast<myPrimaryGenerator>->(runManager->GetPrimaryGenerator());
  auto energyy = myPrimaryGenerator->GetParticleGun()->GetEnergy();

  G4cout << "The energy of photon is: " << energyy
         << " eV, with wavelenght: " << 1240/energyy << " nm." << G4endl; 

but unfortunatly some errors occurs:

/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc: In member function ‘virtual G4VPhysicalVolume* B3::DetectorConstruction::Construct()’:                                                                                 
/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc:347:41: error: ‘myPrimaryGenerator’ does not name a type                                                                                                                
  347 |   auto myPrimaryGenerator = static_cast<myPrimaryGenerator>->(runManager->GetPrimaryGenerator());                                                                                                                                                                    
      |                                         ^~~~~~~~~~~~~~~~~~                                                                                                                                                                                                           
/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc:347:60: error: expected ‘(’ before ‘->’ token                                                                                                                           
  347 |   auto myPrimaryGenerator = static_cast<myPrimaryGenerator>->(runManager->GetPrimaryGenerator());                                                                                                                                                                    
      |                                                            ^~                                                                                                                                                                                                        
      |                                                            (                                                                                                                                                                                                         
/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc:347:60: error: expected primary-expression before ‘->’ token                                                                                                            
  347 |   auto myPrimaryGenerator = static_cast<myPrimaryGenerator>->(runManager->GetPrimaryGenerator());                                                                                                                                                                    
      |                                                            ^~                                                                                                                                                                                                        
/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc:347:62: error: expected unqualified-id before ‘(’ token                                                                                                                 
  347 |   auto myPrimaryGenerator = static_cast<myPrimaryGenerator>->(runManager->GetPrimaryGenerator());                                                                                                                                                                    
      |                                                              ^                                                                                                                                                                                                       
/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc:347:75: error: ‘class G4RunManager’ has no member named ‘GetPrimaryGenerator’; did you mean ‘G4VUserPrimaryGeneratorAction* G4RunManager::userPrimaryGeneratorAction’? (not accessible from this context)
  347 |   auto myPrimaryGenerator = static_cast<myPrimaryGenerator>->(runManager->GetPrimaryGenerator());                                                                                                                                                                    
      |                                                                           ^~~~~~~~~~~~~~~~~~~                                                                                                                                                                        
In file included from /home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc:55:                                                                                                                                               
/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2-install/include/Geant4/G4RunManager.hh:612:36: note: declared protected here                                                                                                                                              
  612 |     G4VUserPrimaryGeneratorAction* userPrimaryGeneratorAction = nullptr;                                                                                                                                                                                             
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                        
/home/mllsml92e13c351e/GEANT4_11_02/geant4-v11.0.2/examples/basic/B3/B3a/src/DetectorConstruction.cc:347:97: error: expected ‘)’ before ‘;’ token                                                                                                                            
  347 |   auto myPrimaryGenerator = static_cast<myPrimaryGenerator>->(runManager->GetPrimaryGenerator());                                                                                                                                                                    
      |                                                                                                 ^                                                                                                                                                                    
      |                                                                                                 )                                                                                                                                                                    
make[2]: *** [CMakeFiles/exampleB3a.dir/build.make:89: CMakeFiles/exampleB3a.dir/src/DetectorConstruction.cc.o] Errore 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/exampleB3a.dir/all] Errore 2
make: *** [Makefile:130: all] Errore 2

Thanks for all, you are helping me so much!

Hi Samuele

Well, like I said, according to your original posting lambda_fotone is a data member of your DetectorConstruction. If it’s a data member, it’s not “global”. So…since you access a global lambda_fotone in your main program it must be a different lambda_fotone. Show us where, in how many different ways you define lambda_fotone.

You can’t. You do not need to know. Geant4 reserves the right to change the internal units at any time. You just have to use *nm and /nm, etc., as appropriate.

  1. You were supposed to substitute the actual name of your primary generator action, which (looking again at your post) is PrimaryGeneratorAction:
  auto myPrimaryGenerator = static_cast<PrimaryGeneratorAction*>(runManager->GetPrimaryGenerator());

To do this stuff you need to have a good grasp of the concepts of object oriented programming, and a good working knowledge of C++.

Cheers
John

1 Like

this is a misunderstanding. you should place all energy and the corresponding property values into the respective vectors, to have it defined for the complete range. then you don’t need the access to the primary‘s energy, and don’t need to specifically set e.g. the reflectivity only/exactly for that energy.

1 Like

If you are curious about the units… System of units

GEANT4 uses default units and SystemofUnits.hh has defined conversion factors. The default of length is mm, so if you define something in cms:

G4int length = 10 * cm;

geant4 has defined cm in terms of mm, i.e. cm= 10. So that line converts your length to mm.

Although allison is right, as long as you specify your units when you define variables its all in the background.

1 Like

Thanks for all the suggestion!!! @allison
Thanks for your interesting comment! @loydms

@weller, I did in the past this job but, in this way, the macro doesn’t work correctly. I mean, it runs (in less time) but don’t generate any .root file:

  G4OpticalSurface* OpTeflonSurface = new G4OpticalSurface("TeflonSurface");
  

	OpTeflonSurface->SetType(dielectric_dielectric);
	OpTeflonSurface->SetModel(unified);
	OpTeflonSurface->SetFinish(groundfrontpainted);

  
 /* G4LogicalBorderSurface* TeflonSurface = */new
    G4LogicalBorderSurface("TeflonSurface", physSferaIntegratrice, physCilindro, OpTeflonSurface);

  
  G4MaterialPropertiesTable* TEFLON_MPT = new G4MaterialPropertiesTable();


  std::vector<G4double> energy = {4.96*eV, 4.94*eV, 4.92*eV, 4.90*eV, 4.88*eV, 4.86*eV, 4.84*eV, 4.82*eV, 4.80*eV, 4.78*eV, 
                                  4.76*eV, 4.74*eV, 4.72*eV, 4.70*eV, 4.68*eV, 4.66*eV, 4.64*eV, 4.62*eV, 4.60*eV, 4.58*eV, 
                                  4.56*eV, 4.54*eV, 4.52*eV, 4.50*eV, 4.48*eV, 4.46*eV, 4.44*eV, 4.42*eV, 4.40*eV, 4.38*eV, 
                                  4.36*eV, 4.34*eV, 4.32*eV, 4.30*eV, 4.28*eV, 4.26*eV, 4.24*eV, 4.22*eV, 4.20*eV, 4.18*eV, 
                                  4.16*eV, 4.14*eV, 4.12*eV, 4.10*eV, 4.08*eV, 4.06*eV, 4.04*eV, 4.02*eV, 4.00*eV, 3.98*eV};

  std::vector<G4double> rindex_teflon = {1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 
                                         1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 
                                         1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 
                                         1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 
                                         1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3};

  std::vector<G4double> reflectivity = {0.959, 0.959, 0.959, 0.960, 0.960, 0.961, 0.961, 0.962, 0.963, 0.963, 
                                        0.964, 0.964, 0.966, 0.966, 0.967, 0.967, 0.968, 0.968, 0.969, 0.970, 
                                        0.970, 0.971, 0.971, 0.972, 0.972, 0.973, 0.973, 0.974, 0.974, 0.975, 
                                        0.976, 0.976, 0.977, 0.977, 0.978, 0.978, 0.979, 0.979, 0.980, 0.980, 
                                        0.981, 0.982, 0.982, 0.983, 0.983, 0.983, 0.983, 0.984, 0.984, 0.984};

  std::vector<G4double> trasmittance =  {0.041, 0.041, 0.041, 0.040, 0.040, 0.039, 0.039, 0.038, 0.037, 0.037, 
                                         0.036, 0.036, 0.034, 0.034, 0.033, 0.033, 0.032, 0.032, 0.031, 0.030, 
                                         0.030, 0.029, 0.029, 0.028, 0.028, 0.027, 0.027, 0.026, 0.026, 0.025, 
                                         0.024, 0.024, 0.023, 0.023, 0.022, 0.022, 0.021, 0.021, 0.020, 0.020, 
                                         0.019, 0.018, 0.018, 0.017, 0.017, 0.017, 0.017, 0.016, 0.016, 0.016};


  std::vector<G4double> absorption =   {1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 
                                        1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 
                                        1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 
                                        1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 
                                        1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um};



  TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon, 50);
  TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption, 50);
  TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity, 50);
  TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, trasmittance, 50);

  
  teflon_mat->SetMaterialPropertiesTable(TEFLON_MPT);
  OpTeflonSurface->SetMaterialPropertiesTable(TEFLON_MPT);


G4OpticalSurface* OpPollutingSurface = new G4OpticalSurface("PollutingSurface");
  

  OpPollutingSurface->SetType(dielectric_dielectric);
  OpPollutingSurface->SetModel(unified);
  OpPollutingSurface->SetFinish(groundfrontpainted);
  
  
 /* G4LogicalBorderSurface* WaterSurface = */ new
    G4LogicalBorderSurface("PollutingSurface", physSferaIntegratrice, physCilindro, OpPollutingSurface);
  
  
  G4MaterialPropertiesTable* POLLUTING_MPT = new G4MaterialPropertiesTable();



  std::vector<G4double> rindex_polluting = {1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 
                                            1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 
                                            1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 
                                            1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 
                                            1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34};

  std::vector<G4double> reflectivity1 = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
                                         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
                                         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
                                         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
                                         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00};

  std::vector<G4double> trasmittance1 = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
                                         100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
                                         100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
                                         100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
                                         100, 100, 100, 100, 100, 100, 100, 100, 100, 100};


  std::vector<G4double> absorption1 = {344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 
                                       344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm,
                                       344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 
                                       344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm,
                                       344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm};



  TEFLON_MPT->AddProperty("RINDEX", energy, rindex_polluting, 50);
  TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption1, 50);
  TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity1, 50);
  TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, trasmittance1, 50);
 
  water_mat->SetMaterialPropertiesTable(POLLUTING_MPT); 
  OpPollutingSurface->SetMaterialPropertiesTable(POLLUTING_MPT);

I no get error… and the syntax seems correct. Where I am making a mistake?
This make me crazy.

Even if you only give one element to each vector, the simulation behaves in the same (wrong) way.

i vaguely remember that energy vector values needs to be in ascending order. is that (still) so?

1 Like

Yes. The optical property vectors must have bins in ascending order by energy (which is really annoying when the underlying data is tabulated by wavelength).

1 Like

I wrote the energy vector in ascending order, but nothing changes…

I’m starting to suppose that there is another kind of error… @weller @mkelsey .

I understood the problem. Maybe geant4 get mad when the vector is written in more than one line, infact:

  //first surface


  G4OpticalSurface* OpTeflonSurface = new G4OpticalSurface("TeflonSurface");
  

	OpTeflonSurface->SetType(dielectric_dielectric);
	OpTeflonSurface->SetModel(unified);
	OpTeflonSurface->SetFinish(groundfrontpainted);

  
 /* G4LogicalBorderSurface* TeflonSurface = */new
    G4LogicalBorderSurface("TeflonSurface", physSferaIntegratrice, physCilindro, OpTeflonSurface);

  
  G4MaterialPropertiesTable* TEFLON_MPT = new G4MaterialPropertiesTable();


  std::vector<G4double> energy = {3.98*eV, 4.00*eV, 4.02*eV, 4.04*eV, 4.06*eV, 4.08*eV, 4.10*eV, 4.12*eV, 4.14*eV, 4.16*eV, 4.18*eV, 4.20*eV, 4.22*eV, 4.24*eV, 4.26*eV, 4.28*eV, 4.30*eV, 4.32*eV, 4.34*eV, 4.36*eV, 4.38*eV, 4.40*eV, 4.42*eV, 4.44*eV, 4.46*eV, 4.48*eV, 4.50*eV, 4.52*eV, 4.54*eV, 4.56*eV, 4.58*eV, 4.60*eV, 4.62*eV, 4.64*eV, 4.66*eV, 4.68*eV, 4.70*eV, 4.72*eV, 4.74*eV, 4.76*eV, 4.78*eV, 4.80*eV, 4.82*eV, 4.84*eV, 4.86*eV, 4.88*eV, 4.90*eV, 4.92*eV, 4.94*eV, 4.96*eV};
  std::vector<G4double> reflectivity = {0.984, 0.984, 0.984, 0.983, 0.983, 0.983, 0.983, 0.982, 0.982, 0.981, 0.980, 0.980, 0.979, 0.979, 0.978, 0.978, 0.977, 0.977, 0.976, 0.976, 0.975, 0.974, 0.974, 0.973, 0.973, 0.972, 0.972, 0.971, 0.971, 0.97, 0.970, 0.969, 0.968, 0.968, 0.967, 0.967, 0.966, 0.966, 0.964, 0.964, 0.963, 0.963, 0.962, 0.961, 0.961, 0.960, 0.960, 0.959, 0.959, 0.959};
  std::vector<G4double> trasmittance = {0.016, 0.016, 0.016, 0.017, 0.017, 0.017, 0.017, 0.018, 0.018, 0.019, 0.02, 0.02, 0.021, 0.021, 0.022, 0.022, 0.023, 0.023, 0.024, 0.024, 0.025, 0.026, 0.026, 0.027, 0.027, 0.028, 0.028, 0.029, 0.029, 0.03, 0.03, 0.031, 0.032, 0.032, 0.033, 0.033, 0.034, 0.034, 0.036, 0.036, 0.037, 0.037, 0.038, 0.039, 0.039, 0.04, 0.04, 0.041, 0.041, 0.041};
  std::vector<G4double> rindex_teflon = {1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3};
  std::vector<G4double> absorption = {1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um, 1.0*um};       


  TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
  TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
  TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
  TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, trasmittance);


  teflon_mat->SetMaterialPropertiesTable(TEFLON_MPT);
  
  OpTeflonSurface->SetMaterialPropertiesTable(TEFLON_MPT);


  //Second surface


  G4OpticalSurface* OpPollutingSurface = new G4OpticalSurface("PollutingSurface");
  

  OpPollutingSurface->SetType(dielectric_dielectric);
  OpPollutingSurface->SetModel(unified);
  OpPollutingSurface->SetFinish(groundfrontpainted);
  
  
 /* G4LogicalBorderSurface* WaterSurface = */ new
    G4LogicalBorderSurface("PollutingSurface", physSferaIntegratrice, physCilindro, OpPollutingSurface);
  
  
  G4MaterialPropertiesTable* POLLUTING_MPT = new G4MaterialPropertiesTable();


  std::vector<G4double> rindex_polluting = {1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.34};
  std::vector<G4double> absorption1 = {344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm, 344.8*cm};
  std::vector<G4double> reflectivity1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 
  std::vector<G4double> trasmittance1 = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100}; 


  POLLUTING_MPT->AddProperty("RINDEX", energy, rindex_polluting);
  POLLUTING_MPT->AddProperty("ABSLENGTH", energy, absorption1);
  POLLUTING_MPT->AddProperty("REFLECTIVITY", energy, reflectivity1);
  POLLUTING_MPT->AddProperty("TRANSMITTANCE", energy, trasmittance1);
  
  
  water_mat->SetMaterialPropertiesTable(POLLUTING_MPT);
  
 
  OpPollutingSurface->SetMaterialPropertiesTable(POLLUTING_MPT);

the simulation works well.

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