1
$\begingroup$

I'm trying to add a colour to the LogicalVolume which has been renamed to TrackerLogical in Geant4. I get the error that fVisAttributes and visAttributes are undefined although I have defined them in the #include section as .hh files.

The primary framework I have used is that of exampleB1 and I am trying to add color using exampleB5 's approach by applying G4VisAttributes. I have referred to this as a guide: https://github.com/Geant4/geant4/blob/master/examples/basic/B5/src/B5DetectorConstruction.cc

I have included the necessary bits in the #include section as shown in example B5, and have included a line for fVisAttributes in the section B1DetectorConstruction::B1DetectorConstruction() but I get the error messages when I run -jN after adding the following section of code before the last line ( return physWorld) :

 visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9));
 visAttributes->SetVisibility(false);
 trackerLogical->SetVisAttributes(visAttributes);
 fVisAttributes.push_back(visAttributes);

This is the error message I get:

home/neha/G4WORk/B1/src/B1DetectorConstruction.cc: In constructor ‘B1DetectorConstruction::B1DetectorConstruction()’:
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc:53:3: error: class ‘B1DetectorConstruction’ does not have any field named ‘fVisAttributes’
   53 |   fVisAttributes()
      |   ^~~~~~~~~~~~~~
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc: In member function ‘virtual G4VPhysicalVolume* B1DetectorConstruction::Construct()’:
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc:202:2: error: ‘visAttributes’ was not declared in this scope; did you mean ‘G4VisAttributes’?
  202 |  visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9));
      |  ^~~~~~~~~~~~~
      |  G4VisAttributes
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc:205:2: error: ‘fVisAttributes’ was not declared in this scope; did you mean ‘G4VisAttributes’?
  205 |  fVisAttributes.push_back(visAttributes);
      |  ^~~~~~~~~~~~~~
      |  G4VisAttributes
make[2]: *** [CMakeFiles/exampleB1.dir/build.make:89: CMakeFiles/exampleB1.dir/src/B1DetectorConstruction.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/exampleB1.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

What is causing the issue and how can I resolve this? I am still a beginner with Geant4 and may need some fundamental explanations (in simple/layman's terms preferably). Thank you!

$\endgroup$
4
  • $\begingroup$ I've migrated this over from Physics because it's really a pure software question. $\endgroup$
    – rob
    Sep 4 '20 at 21:21
  • 1
    $\begingroup$ This looks like more of a debugging question, so SciComp.SE is not really a place to answer it either. However, it is not that those attributes are not defined, they are not declared. For example, if you change visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9)); to G4VisAttributes * visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9));, then the error on line 202 will go away. Similarly fVisAttributes is not a declared variable either. Line 53 is trickier, it may be that you forgot to put a semicolon or tried to use a variable as a function $\endgroup$ Sep 5 '20 at 2:33
  • $\begingroup$ Thank you for this. I was able to eradicate the error in line 202 by declaring it the way you have suggested. In the case of line 53, what does it mean by class ‘B1DetectorConstruction’ does not have any field named ‘fVisAttributes’ ? How can I create this field? I'll be thankful if you could guide me to a relevant forum if SciComp.SE is not the ideal place to discuss this. $\endgroup$
    – A.Sa
    Sep 5 '20 at 11:41
  • $\begingroup$ I don't really know, it is mostly a coding question though. C++ is an object oriented language and there is a hierarchy of structures. See w3schools.com/cpp/cpp_classes.asp for example. MyClass is a class, it has public attributes myNum and myString. Now, a special constructor -which initializes myNum to a default value- for MyClass can be implemented as MyClass(string inString) : myNum(5) { myString = inString;}. In your case B1DetectorConstruction does not have any attribute named fVisAttributes $\endgroup$ Sep 7 '20 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.