Get material in detector construction from other file

Hello, I defined the acrylic material in a local material table file:
MGGerdaLocalMaterialTable.cc (4.9 KB)
MGGerdaLocalMaterialTable.hh (2.7 KB)

I’ve to get the acrylic material in the detector construction

G4Material* Acrylic = G4Material::GetMaterial("Acrylic");

B1DetectorConstruction.cc (60.0 KB)

but I get the error

image

how to get the material definition from the local material file?

Where does MGGerdaLocalMaterials::CreateMaterials() get called? If that function isn’t called, then none of the code in the function ever gets executed.

Hello @mkelsey how to call a function from an external file?

This is a general C++ question. C++ is a compiled language. I recommend looking up some basic C++ programming resources in order to understand how to program in C++.

Sincerly I know that in C++ to call a function from another file I’ve:

  1. To define the function in the hh file
  2. To include the the hh file in the wanted file.
  3. To call the function in the wanted file in this way:
function();

but it doesn’t work. Ie.

  1. In MGGerdaLocalMaterialTable.hh there is the definition of the function
class MGGerdaLocalMaterialTable 
{
public:

  //default constructor
  MGGerdaLocalMaterialTable();

  //destructor
  ~MGGerdaLocalMaterialTable();

  //public interface

  void CreateMaterials();
  void AddNewMaterial();
  1. In B1detectorconstruction.cc I included

``#include “MGGerdaLocalMaterialTable.hh”`

  1. In B1detectorconstruction.cc I called the function
    MGGerdaLocalMaterialTable::CreateMaterials(); `

but I get the error

the traslation of the error is : not valid call of member of no static function

MGGerdaLocalMaterialTable.hh (2.7 KB)
B1SteppingAction.cc (3.1 KB)

Please, can you say me how to fix it?

You don’t have that class defined with static functions. So you need to instantiate the object, then call the function via the instantiated object.

Thank you, I did it!

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