-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Geant4-object pointer comparisons instead of string-comparisons where possible #1376
Comments
I don't think we want a namespace ptr_retrieval {
const G4VProcess* GetPhotonuclearProcess() const {
return GetProcess(G4Gamma::Definition(), "photonNuclear");
}
const G4VProcess* GetProcess(G4ParticleDefinition* particle, std::string processName) const {
const auto manager {particle->GetProcessManager()};
const auto processes {manager->GetProcessList()};
for (int i{0}; i < processes->size(); ++i) {
const auto process {(*processes)[i]};
const auto name {process->GetProcessName()};
if (name.contains(processName)) {
return process;
}
}
// for processes from the particle table, I can't think of a situation where this would be useful
// maybe code-in the exception here?
return nullptr;
}
G4Region* GetRegion(std::string name) {
return G4RegionStore::GetInstance()->GetRegion(name);
}
} // namespace ptr_retrieval and then the call-site would look readable like auto pn = ptr_retrieval::GetPhotonuclearProcess(); |
Yeah, that seems sensible :) |
So where should this go? And then have a GetProcess for all other kinda processes? It's not clear to me how the proposed snippet gets rid of string comparisons, there is still a But I guess if we do this, it will resolve #1286 by having the same things for the detector elements, right? |
This would be utility functions available from within SimCore and then the places that know they need to do region or volume checks (e.g. in filters) would store the values of these pointers and then only use the values of the pointers during running. |
You only do the string comparison once :) |
We have a lot of code in SimCore and Biasing which does things like
Where thing can be something like
This has two big downsides
ldmx-sw/Biasing/src/Biasing/EcalProcessFilter.cxx
Lines 101 to 111 in 28fd696
This is a bug. There is no physical volume called
hcal_PV
so that condition will never trigger. The volume in question happens to be called "hadronic_calorimeter" which differs from all the others that have names liketagger_PV
etc. If we are using pointers as our comparison tool, we can enforce at configuration time that these are initialized and throw otherwise (so issues like the hcal name here would be caught).I think the best way to do this would be to have a helper type in SimCore that can be used to get the various pointers people might need and make sure that things like biasing wrappers are handled correctly.
etc
The text was updated successfully, but these errors were encountered: