Home | News | Documentation | Download

Undeclared identifier error (material)

Hello, I am a newbie to ROOT programming. I am using ROOT
version : v6-24-06@v6-24-06 . I am trying to use the following code, but end up getting the errors:

error: use of undeclared identifier ‘Vacuum’
*TGeoVolume top = geom->MakeBox(“TOP”,Vacuum, 110, 110, 110);

  •                                  ^*
    

ROOT_prompt_36:1:36: error: use of undeclared identifier ‘Vacuum’
*TGeoVolume D = geom->MakeBox(“D”, Vacuum, 100, 100, 100);

  •                               ^*
    

ROOT_prompt_39:1:42: error: use of undeclared identifier ‘Vacuum’
*TGeoVolume box2 = geom->MakeBox(“box2”, Vacuum, 1.5,0.15,0.15);

  •                                     ^*
    

ROOT_prompt_44:1:42: error: use of undeclared identifier ‘cs’
*TGeoVolume comp = new TGeoVolume(“COMP”,cs);comp->SetLineColor(5);
^

The code I am trying to use is below. Any help would be greatly appreciated.

#include “TGeoManager.h”

#include< iostream>

#include< cmath>

using namespace std;

void pet()
{

// gStyle->SetCanvasPreferGL(true);

gSystem>Load(“libGeom”);

TGeoManager *geom = new TGeoManager(“world”, “Simple geometry”);

//— define some materials

TGeoMaterial *matPb = new TGeoMaterial(“Pb”, 207.2, 82, 11.34);

TGeoMaterial *matVacuum = new TGeoMaterial(“Vacuum”, 0,0,0);

TGeoMaterial *matAl = new TGeoMaterial(“Al”, 26.98,13,2.7);

TGeoMaterial *matSi = new TGeoMaterial(“Si”, 28.0855,14,2.3290);

//— define some media
TGeoMedium *Vacuum = new TGeoMedium(“Vacuum”, 1, matVacuum);

TGeoMedium *Al = new TGeoMedium(“Al”,2, matAl);

TGeoMedium *Pb= new TGeoMedium(“Pb”,3, matPb);

TGeoMedium *Si = new TGeoMedium(“Si”,4, matSi);

//— make mixture lead glass

TGeoElementTable *table = gGeoManager->GetElementTable();

TGeoElement *el1 = table->GetElement(8);
TGeoElement *el2 = table->GetElement(14);
TGeoElement *el3 = table->GetElement(22);
TGeoElement *el4 = table->GetElement(33);
TGeoElement *el5 = table->GetElement(82);

TGeoMixture *glass = new TGeoMixture(“glass”,5,6.22);

glass->AddElement(el1,0.1564); glass->AddElement(el2,0.0809);

glass->AddElement(el3,0.0081);

glass->AddElement(el4,0.0027);

glass->AddElement(el5,0.7519);

printf("___________________________________________________________\n"); printf(“Lead glass:\n”);
glass->Print();

TGeoMedium *mglass = new TGeoMedium(“glass”,5, glass);

//define the top container volume

Double_t worldx = 110.;

Double_t worldy = 110.;

Double_t worldz = 110.;

TGeoVolume *top = geom->MakeBox(“TOP”,Vacuum, 110, 110, 110);

top->SetLineColor(kMagenta);

geom->SetTopVolume(top);

top->SetVisibility(kFalse)

// make detector

TGeoVolume *D = geom->MakeBox(“D”, Vacuum, 100, 100, 100);

D->SetVisibility(kFalse)
// make boxes
TGeoVolume *box1 = geom->MakeBox(“box1”,Al,1.5,0.2,0.2);

TGeoVolume *box2 = geom->MakeBox(“box2”, Vacuum, 1.5,0.15,0.15);

TGeoVolume *box3 = geom->MakeBox(“box3”,mglass,1.5,0.15,0.15);

// SiPm Silicon
TGeoVolume *box4 = geom->MakeBox(“box4",Si,0.05,0.15,0.15);

TGeoTranslation *t1 = new TGeoTranslation(“t1”,1.55,0,0);
t1->RegisterYourself();

//composition
TGeoCompositeShape *cs = new TGeoCompositeShape(“cs”,"((box1-box2)+box3)+box4:t1");

TGeoVolume *comp = new TGeoVolume(“COMP”,cs);
comp->SetLineColor(5);

D->AddNode(comp,1);

Hi,

you have a typo:

should read

gSystem->Load("libGeom");

And also

and

should probably read

top->SetVisibility(false);

and

D->SetVisibility(false);

Hi @Yasenya,

Welcome to the ROOT forum. Find below the changes required for your code to be syntactically correct.

This should be

gSystem->Load("libGeom");

should be changed to (note the added semicolon):

top->SetVisibility(kFALSE);

should be changed to:

D->SetVisibility(kFALSE);

Also note that, due to probably having copied the code from somewhere else, all the typographic quotes characters, i.e. and , should be changed to ".

Cheers,
J.

Thank you so much @jalopezg for your reply. I corrected my typing errors accordingly. However, I still get the following errors for “vacuum” . Is there any way to fix this?

use of undeclared identifier ‘Vacuum’
TGeoVolume *top = geom->MakeBox(“TOP”,Vacuum, 110, 110, 110);
^
ROOT_prompt_332:1:36: error: use of undeclared identifier ‘Vacuum’
TGeoVolume *D = geom->MakeBox(“D”, Vacuum, 100, 100, 100);
^
ROOT_prompt_335:1:42: error: use of undeclared identifier ‘Vacuum’
TGeoVolume *box2 = geom->MakeBox(“box2”, Vacuum, 1.5,0.15,0.15);

Thank you @yus for your help.

I corrected my typing errors accordingly. However, I still get the following errors for “vacuum” . Is there any way to fix this?

use of undeclared identifier ‘Vacuum’
TGeoVolume *top = geom->MakeBox(“TOP”,Vacuum, 110, 110, 110);
^
ROOT_prompt_332:1:36: error: use of undeclared identifier ‘Vacuum’
TGeoVolume *D = geom->MakeBox(“D”, Vacuum, 100, 100, 100);
^
ROOT_prompt_335:1:42: error: use of undeclared identifier ‘Vacuum’
TGeoVolume *box2 = geom->MakeBox(“box2”, Vacuum, 1.5,0.15,0.15);

Try this version with all the proposed changes already applied:

#include "TGeoManager.h"
#include <iostream>
#include <cmath>

using namespace std;

void pet() {
  // gStyle->SetCanvasPreferGL(true);
  gSystem->Load("libGeom");
  TGeoManager *geom = new TGeoManager("world", "Simple geometry");

  //— define some materials
  TGeoMaterial *matPb = new TGeoMaterial("Pb", 207.2, 82, 11.34);
  TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
  TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
  TGeoMaterial *matSi = new TGeoMaterial("Si", 28.0855,14,2.3290);

  //— define some media
  TGeoMedium *Vacuum = new TGeoMedium("Vacuum", 1, matVacuum);
  TGeoMedium *Al = new TGeoMedium("Al",2, matAl);
  TGeoMedium *Pb = new TGeoMedium("Pb",3, matPb);
  TGeoMedium *Si = new TGeoMedium("Si",4, matSi);

  //— make mixture lead glass
  TGeoElementTable *table = gGeoManager->GetElementTable();

  TGeoElement *el1 = table->GetElement(8);
  TGeoElement *el2 = table->GetElement(14);
  TGeoElement *el3 = table->GetElement(22);
  TGeoElement *el4 = table->GetElement(33);
  TGeoElement *el5 = table->GetElement(82);

  TGeoMixture *glass = new TGeoMixture("glass",5,6.22);
  glass->AddElement(el1,0.1564);
  glass->AddElement(el2,0.0809);
  glass->AddElement(el3,0.0081);
  glass->AddElement(el4,0.0027);
  glass->AddElement(el5,0.7519);

  printf("___________________________________________________________\n"); printf("Lead glass:\n");
  glass->Print();

  TGeoMedium *mglass = new TGeoMedium("glass",5, glass);

  //define the top container volume
  Double_t worldx = 110.;
  Double_t worldy = 110.;
  Double_t worldz = 110.;

  TGeoVolume *top = geom->MakeBox("TOP",Vacuum, 110, 110, 110);
  top->SetLineColor(kMagenta);
  geom->SetTopVolume(top);
  top->SetVisibility(false);

  // make detector
  TGeoVolume *D = geom->MakeBox("D", Vacuum, 100, 100, 100);
  D->SetVisibility(false);

  // make boxes
  TGeoVolume *box1 = geom->MakeBox("box1",Al,1.5,0.2,0.2);
  TGeoVolume *box2 = geom->MakeBox("box2", Vacuum, 1.5,0.15,0.15);
  TGeoVolume *box3 = geom->MakeBox("box3", mglass, 1.5,0.15,0.15);

  // SiPm Silicon
  TGeoVolume *box4 = geom->MakeBox("box4", Si, 0.05,0.15,0.15);

  TGeoTranslation *t1 = new TGeoTranslation("t1", 1.55,0,0);
  t1->RegisterYourself();

  //composition
  TGeoCompositeShape *cs = new TGeoCompositeShape("cs","((box1-box2)+box3)+box4:t1");

  TGeoVolume *comp = new TGeoVolume("COMP", cs);
  comp->SetLineColor(5);
  D->AddNode(comp, 1);
}

You do not need all the includes and the using namespace std. Just drop these lines:

Also, what do you mean when you say that

?
After having run your code I get the following canvas:

@yus Interestingly it managed to work without any changement to the last code sequence I posted, maybe there was a problem with the terminal. Thank you for your help.

@jalopezg It managed to work now, It was a big problem for my project. Thank you so much for your help.

@Yasenya You are very welcome! Please, don´t forget to mark the topic as solved.

Cheers.

1 Like