Message: Re: Modification of BremSplittingProcess Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: Modification of BremSplittingProcess 

Forum: Event and Track Management
Re: Question Modification of BremSplittingProcess (Oliver Diaz)
Date: 17 Feb, 2011
From: Michael H. Kelsey <Michael H. Kelsey>

On Tue, 01 Feb 2011 17:22:23 GMT, Oliver Diaz wrote:
> I am a bit confused with the use of G4VParticleChange and
> G4ParticleChange. At some point, when casting, I got Null pointer. Here
> you have the error: virtual G4VParticleChange*
> BremSplittingProcess::PostStepDoIt(const G4Track&, const G4Step&):
> Assertion `0 != particleChange' failed. Abort
> 
> This is probably due to my small knowledge of C++, so sorry if the
> question is too simple, but I really appreciate guidance on this issue.

It could be useful for you to take a general course on C++ programming, or at least go through a good reference systematically. I can explain your specific issue, and you should be able to use the terminology as "search terms" to learn more.

> This is part of my code:
> 
> G4VParticleChange* BremSplittingProcess::PostStepDoIt(const G4Track& track, const G4Step& step)
> {
>  ...
>    G4ParticleChange* particleChange(0); // G4VParticleChange in the example hands-on 5

Yes, this should be declared as a G4VParticleChange*. In GEANT4, we use the "V" in the name to remind us that the class is _virtual_. That is, it is a _base_class_ which can be used to represent several different concrete _subclasses_ with similar, but not identical, properties.

G4ParticleChange is just one of those concrete subclasses, so what you've done with that declaration is say that your "particleChange" pointer can only ever be assigned to point to a *concrete* G4ParticleChange object, and not any of the other related objects that might be returned by PostStepDoIt().

>  ...
>    particleChange = dynamic_cast<G4ParticleChange*>(pRegProcess->PostStepDoIt(track, step)); // pRegProcess->PostStepDoIt(track, step) in the example hands-on 5

This is a clue that you've done something wrong. All PostStepDoIt() functions are required to return a pointer to the _base_class_ G4VParticleChange. They might create any of several different concrete _subclasses_, and you (the client code) does not have to know (and shouldn't bother to know) which subclass it is.

When you invoke the "dynamic_cast" function, it checks to see whether the argument (i.e., the G4VParticleChange* returned by PostStepDoIt) is actually a pointer to the specific concrete subclass type you've specified (in this case, G4ParticleChange). If the object is of that specific type, then you get the same pointer, but as a pointer to the subclass. If the object is of a *different* subclass than what you specified, then dynamic_cast returns 0.

The bottom line is that you should be declaring your "particleChange" to be a pointer to the base class, and not trying to second-guess the software.

     -- Michael Kelsey

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Modification of BremSplittingProcess   (Oliver Diaz - 18 Feb, 2011)
 Add Message Add Message
to: "Re: Modification of BremSplittingProcess"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]