Not declared identifier

Hello, I’m adding some flags to my simulation. Now I’m adding a flag to choose which particle outgoing the target to store in the ROOT file.

Then in the I wrote (to get primary positrons or primary electrons)

G4bool PrimaryPositronElectronExitFlag=true;

in the

B1SteppingAction::B1SteppingAction(B1EventAction* eventAction, G4bool PrimaryPositronElectronExitFlag)
: G4UserSteppingAction(),

G4int particle;
G4int particlebar;
G4String parentid;

if (fPrimaryPositronElectronExitFlag){

parentid = “step->GetTrack()->GetParentID()==00”;

if(NextVol && ThisVol->GetName()=="Target2" && NextVol->GetName()=="World" && parentid && (step->GetTrack()->GetDynamicParticle()->GetPDGcode()==particle || step->GetTrack()->GetDynamicParticle()->GetPDGcode()==particlebar )) {

in the steppingaction.hh

    B1SteppingAction(B1EventAction* eventAction, G4bool PrimaryPositronElectronExitFlag);

    G4bool fPrimaryPositronElectronExitFlag;

in the "
SetUserAction(new B1SteppingAction(eventAction, PrimaryPositronElectronExitFlag));

but I get this error

    C:\B1\src\,51): error C2065: 'PrimaryPositronElectronExitFlag': identificatore non dichiara
    to [C:\B1\B1-build\exampleB1.vcxproj]

i (2.9 KB) (6.8 KB)
B1SteppingAction.hh (2.5 KB) (4.9 KB)

Thank you

PrimaryPositronElectronExitFlag is not known in your B1ActionInitialization.

You could create for example a fPrimaryPositronElectronExitFlag in B1ActionInitialization.hhas you did in steppingaction.hh, and pass the parameter in line 100 in

runManager->SetUserInitialization(new B1ActionInitialization(PrimaryPositronElectronExitFlag));

Hello @weller,
in the I added

B1ActionInitialization::B1ActionInitialization(G4bool PrimaryPositronElectronExitFlag)
 : G4VUserActionInitialization()

SetUserAction(new B1SteppingAction(eventAction, PrimaryPositronElectronExitFlag));

in B1Actioninizialization.hh
B1ActionInitialization(G4bool PrimaryPositronElectronExitFlag);
G4bool fPrimaryPositronElectronExitFlag;

runManager->SetUserInitialization(new B1ActionInitialization(PrimaryPositronElectronExitFlag));

but I get this error
C:\B1\include\B1ActionInitialization.hh(40,28): error C2061: errore di sintassi: identificatore 'G4bool' (compilazione del file di origine C:\B1\src\B1Acti [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1ActionInitialization.hh(48,12): error C3646: 'fPrimaryPositronElectronExitFlag': identificatore di override sconosciuto (compilazione del f
ile di origine C:\B1\src\ [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1ActionInitialization.hh(48,44): error C4430: identificatore di tipo mancante, verrà utilizzato int. Nota: default-int non è più supportato
in C++ (compilazione del file di origine C:\B1\src\ [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\src\,2): error C2511: 'B1ActionInitialization::B1ActionInitialization(G4bool)': funzione membro in overload non trovata i
n 'B1ActionInitialization' [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\include\B1ActionInitialization.hh(37): message : vedere la dichiarazione di 'B1ActionInitialization' [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\src\,34): error C2612: 'identificatore' finale non valido nell'elenco degli inizializzatori di basi/membri [C:\B1\B1-buil
C:\B1\src\,1): fatal error C1004: fine del file imprevista [C:\B1\B1-build\exampleB1.vcxproj] (3.0 KB) (6.8 KB) (8.4 KB) (5.0 KB)
PhysicsList.hh (3.0 KB)
PhysicsListMessenger.hh (2.7 KB)
B1SteppingAction.hh (2.5 KB) (4.9 KB)

B1ActionInitialization.hh (2.3 KB)

You are running into basic C++ programming issues, nothing specific to Geant4. C++ is a strongy typed language. Every variable you use must be declared, and initialized with a specific value, before you reference it. I would recommend a good, introductory C++ text in order to understand these issues.

Hello @mkelsey I declared in B1Actioninizialization.hh

B1ActionInitialization(G4bool PrimaryPositronElectronExitFlag);
G4bool fPrimaryPositronElectronExitFlag;

and in

B1ActionInitialization::B1ActionInitialization(G4bool PrimaryPositronElectronExitFlag)
 : G4VUserActionInitialization()

but I get the error…so I can’t understand…
Please, can you write the code to fix this?

You’re missing a comma after the base class initializer, and you should not have a comma after the data member initializer.

Thank you @mkelsey i compiled and I runned (but I really didn’t see the comma…I did copy and paste from the stepping action and I did a mistake during the copy and paste without see it!)

…but now I think to have a Geant 4 problem…
in the steppingaction I’ve

G4String getparticles;
G4String ThisVolume;
G4String NextVolume;

if (fPrimaryPositronElectronExitFlag){
	ThisVolume= "Target2";
	NextVolume= "World";
	getparticles = "NextVol && ThisVol->GetName()==ThisVolume && NextVol->GetName()==NextVolume && step->GetTrack()->GetParentID()==00 && (step->GetTrack()->GetDynamicParticle()->GetPDGcode()==11 || step->GetTrack()->GetDynamicParticle()->GetPDGcode()==-11)";

			if(getparticles) { 
			 		    int pdg = step->GetTrack()->GetParticleDefinition()->GetPDGEncoding();
			 			analysisManager->FillNtupleDColumn(1,0, pdg);
			 			double kinEnergy = step->GetTrack()->GetDynamicParticle()->GetKineticEnergy();
			 			analysisManager->FillNtupleDColumn(1,1, kinEnergy);

then I should selecto only e+/- primary particles…instead in the root file I see phtons…

then I don’t understand the reason because of it selectes secondary photons… (6.8 KB)

PS. I also tried to write

getparticles = "NextVol && ThisVol->GetName()==ThisVolume && NextVol->GetName()==NextVolume && step->GetTrack()->GetParentID()==00 && (step->GetTrack()->GetDynamicParticle()->GetPDGcode()==13 || step->GetTrack()->GetDynamicParticle()->GetPDGcode()==-13)";

but I still get electrons and photons…then it looks like that the selection doesn’t work…

Please get some basic texts and instruction in writing C++. This is not Python.
You don’t create strings and expect them to be “interpreted” at run time. You write actual code.

Sorry @mkelsey …I don’t understand what you mean…here C++ Strings there is an example of string and it’s made like I did…so what is strong in my code?

G4String var1 = "This is a text string";    // this is just a bunch of characters
G4String var2 = "E>0 && x<5*cm";        // this is *also* just a bunch of characters

 if (var2) {     // This tests whether the var2 variable is not equal to zero

That if statement does not evaluate the string as math. The string is just a bunch of characters (bytes in memory). All it is doing is testing that the variable var2 is located at a memory location which is not 0x00000000.

If you want to evaluate a condition, then you put the condition into the if statement:

if (E>0 && x < 5*cm) {     // This tests the _variables_ E and x

Thank you @mkelsey i see…and isn’t there a way to do what I wanted to do (i.e. to define a text to be evalueted?

I explain…I have there possibilities

  1. Primari particles outgoing the targets
  2. Secondary muons outgoing the targets
  3. Photons outgoing the world (ie cracking for no step )…then I would like to define the 3 cases.
    Them i should define a “string” or other kind of variable to write in the if that It’s interpreted by the if

Is there i Geant4 something to do that?

No. Geant4 is a C++ application. You write C++ code, using the features and limitations of the language. You already wrote the conditional expression, just stop putting it in quotes, and put into the if expression directly. Please learn the basics of C++, so that you will have a clear understanding of how the software is written.

I have heard of a Python interface to C++, which lets you do things in Python instead, but I have never used it myself.

Thank you @mkelsey !