faca87
October 26, 2022, 3:07pm
1
Hello, I should get energy of primary photons.
I wrote a stackingaction starting from the stackingaction of Testem1, but I get empty histograms.
Notice that I also tried to delete the
if (parentID == 0 && particleName == "gamma")
if (energy > 0)
but also deleting them I get empty histograms.
During the compiling I get this warning (traslation: no all control paths give back a value)
StackingAction.cc (3.4 KB)
StackingAction.hh (2.4 KB)
On the compiler warning, look at the if/else
block in ClassifyNewTrack
- that member function must return a value. Does every branch of the if/else
result in a return
?
faca87
October 27, 2022, 9:27am
3
Hello @bmorgan
I tried to remove all the if else (see attachment)
but I get the same warning “no all control paths give back a value” and the same problem (empty histogram).
Then the problem isn’t the if/else, but something else in the stackingaction.
Do you have any idea?
StackingAction.cc (3.4 KB)
StackingAction.hh (2.4 KB)
EDIT:
I just noticed that I’ve to call the stacking action in actioninizialization.cc, then I added in actioninizialization:
#include "StackingAction.hh"
....
void B1ActionInitialization::Build() const
{
SetUserAction(new B1PrimaryGeneratorAction);
B1RunAction* runAction = new B1RunAction;
SetUserAction(runAction);
B1EventAction* eventAction = new B1EventAction(runAction);
SetUserAction(eventAction);
SetUserAction(new B1SteppingAction(eventAction, fGetKinematicsFlag));
SetUserAction(new StackingAction);
}
but now I still get the warning “no all control paths give back a value” and I also get the error
bmorgan
October 27, 2022, 10:55am
4
Let’s look at the code giving the warning first :
G4ClassificationOfNewTrack
StackingAction::ClassifyNewTrack(const G4Track* track)
{
//This code looks for gammas emitted by nuclear decays
//and counts how many primary particles are emitted in the decay
G4int parentID = track->GetParentID();
G4String particleName = track->GetDefinition()->GetParticleName();
G4String particleType = track->GetDefinition()->GetParticleType();
G4int pdggamma;
G4double energy;
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
// if (parentID == 0 && particleName == "gamma")
//{
pdggamma = track->GetParticleDefinition()->GetPDGEncoding();
energy = track->GetDynamicParticle()->GetKineticEnergy();
analysisManager->FillNtupleDColumn(2,0, pdggamma);
//if (energy > 0)
// {
analysisManager->FillNtupleDColumn(2,1, energy/keV);
analysisManager->FillH1(1, energy/keV);
//}
// }
//else
// return fUrgent;
}
The function must return a G4ClassificationOfNewTrack
value - where in the above implementation does this occur?
1 Like
faca87
October 27, 2022, 2:40pm
5
Thank you, I solved!
They were return missing!
system
Closed
November 3, 2022, 2:41pm
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.