# Undeclared identifier error (material)

**URL:** <https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361>\
**Category:** Newbie\
**Created:** [January 12, 2022, 4:24pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361 "2022-01-12T16:24:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yasenya](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@Yasenya](https://root-forum.cern.ch/u/Yasenya)\
**Post date:** [January 12, 2022, 4:24pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/1 "2022-01-12T16:24:52Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [January 12, 2022, 4:47pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/2 "2022-01-12T16:47:34Z")

</div>

Hi,

you have a typo:

> [@Yasenya](#):
>
> gSystem\>Load(“libGeom”);

should read

```c++
gSystem->Load("libGeom");

```

And also

> [@Yasenya](#):
>
> top-\>SetVisibility(kFalse)

and

> [@Yasenya](#):
>
> D-\>SetVisibility(kFalse)

should probably read

```c++
top->SetVisibility(false);

```

and

```c++
D->SetVisibility(false);

```

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 12, 2022, 4:51pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/3 "2022-01-12T16:51:32Z")

</div>

Hi @Yasenya,

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

> [@Yasenya](#):
>
> gSystem\>Load(“libGeom”);

This should be

```c++
gSystem->Load("libGeom");

```

> [@Yasenya](#):
>
> top-\>SetVisibility(kFalse)

should be changed to (note the added semicolon):

```c++
top->SetVisibility(kFALSE);

```

> [@Yasenya](#):
>
> D-\>SetVisibility(kFalse)

should be changed to:

```c++
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.

---

<div class="post-metadata">

**Author:** ![Yasenya](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@Yasenya](https://root-forum.cern.ch/u/Yasenya)\
**Post date:** [January 12, 2022, 4:57pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/4 "2022-01-12T16:57:03Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![Yasenya](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@Yasenya](https://root-forum.cern.ch/u/Yasenya)\
**Post date:** [January 12, 2022, 5:09pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/5 "2022-01-12T17:09:13Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 12, 2022, 5:15pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/6 "2022-01-12T17:15:44Z")

</div>

Try this version with all the proposed changes already applied:

```c++
#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);
}

```

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [January 12, 2022, 6:08pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/9 "2022-01-12T18:08:43Z")

</div>

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

> [@Yasenya](#):
>
> #include “TGeoManager.h”
> 
> #include “TGeoManager.h”  
> #include  
> #include
> 
> **using**  **namespace** std;

Also, what do you mean when you say that

> [@Yasenya](#):
>
> there isn’t any response (The design I am trying to make does not appear)

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

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/7/1710d569b2fa17796810a201fbaca12993b16ac9.png)

---

<div class="post-metadata">

**Author:** ![Yasenya](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@Yasenya](https://root-forum.cern.ch/u/Yasenya)\
**Post date:** [January 12, 2022, 6:42pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/10 "2022-01-12T18:42:03Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Yasenya](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@Yasenya](https://root-forum.cern.ch/u/Yasenya)\
**Post date:** [January 12, 2022, 6:45pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/11 "2022-01-12T18:45:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 13, 2022, 12:02pm UTC](https://root-forum.cern.ch/t/undeclared-identifier-error-material/48361/12 "2022-01-13T12:02:08Z")

</div>

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

Cheers.
