-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add distance to nearest surface field to GermaniumOutputScheme #182
Conversation
Ah, right, the tests would also have to be adjusted to the ntuple size. After we have decided if this is supposed to be a permanent part of the tuple or only added via macro |
I have another idea for a more definitive check:
edit: I mean some plots like this in the WIP reboost docs Of course without the difference in surface types |
Ah, that looks like a very good idea! I will have a look at the docs next week, thanks for the references! |
Apart from those comments, thank you very much for the test. We already did assume this, but had not looked deeper in it. The overall performance looks also quite promising. It might be also worth comparing the performance again with the geometry with only a single detector. (this "microscopic" check would be - sort of - an upper bound on simulation slowdon)
what do you think, @tdixon97?
yes and no. The detectors are polycones, but might have subtractions of other volumes (i.e. boxes). But like you, I would also assume that Geant4 is pretty well validated in the geometry part. I would be slightly more worried about performance with the subtractions: It might also be interesting to repeat the "microscopic" performance measurement just with P00664b. (The visual check of distance does not work with this detector, as the radial symmetry is broken.) |
Thanks a lot @EricMEsch! This looks very promising.
If you are right we don't even need to calculate distances in post-processing.
I guess that a better figure for the performance penalty would be shooting electrons uniformly in germanium. As mentioned by @ManuelHu, it would be good to check the results with the few detectors made with subtractions. |
I will do the "microscopic" part mentioned by @ManuelHu and can also change gammas to electrons and shoot them at the detector as you mentioned @gipert. I can also make additional tests for the subtraction solids. I would not expect there to be any issues with subtractions, as the G4SubtractionSolid::DistanceToOut( const G4ThreeVector& p ) const
{
G4double dist=0.0;
if( Inside(p) == kOutside )
{
... // (there is a warning print here)
}
else
{
dist= std::min(fPtrSolidA->DistanceToOut(p),
fPtrSolidB->DistanceToIn(p) ) ;
}
return dist;
} |
This is great, I agree the test with electrons is more meaningfull.
Unfortunately, this cannot replace totally computation of distances in post processing since you need distances to only some surfaces. But probbaly, having this precomputed still enables a dramatic speed up.
…________________________________
From: Eric Esch ***@***.***>
Sent: Saturday, December 7, 2024 5:09 PM
To: legend-exp/remage ***@***.***>
Cc: Dixon, Toby ***@***.***>; Mention ***@***.***>
Subject: Re: [legend-exp/remage] Add distance to nearest surface field to GermaniumOutputScheme (PR #182)
⚠ Caution: External sender
I will do the "microscopic" part mentioned by @ManuelHu<https://github.com/ManuelHu> and can also change gammas to electrons and shoot them at the detector as you mentioned @gipert<https://github.com/gipert>. I can also make additional tests for the subtraction solids.
I would not expect there to be any issues with subtractions, as the DistanceToOut() function of G4SubtractionSolid is just a few lines of code calling to the original volumes
G4SubtractionSolid::DistanceToOut( const G4ThreeVector& p ) const
{
G4double dist=0.0;
if( Inside(p) == kOutside )
{
... // (there is a warning print here)
}
else
{
dist= std::min(fPtrSolidA->DistanceToOut(p),
fPtrSolidB->DistanceToIn(p) ) ;
}
return dist;
}
—
Reply to this email directly, view it on GitHub<#182 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ANSET46CWGQTWMPBBFHTNM32EMMTDAVCNFSM6AAAAABTGHTTESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRVGIZDQMRWGE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I have done the check @ManuelHu proposed, for Detector V02160A (The only subtraction solid i think?) (left) and detector B00035B (right). Looks promising: I am not 100% sure about the subtraction solid, as detector one would expect a small dent at the bottom of one side, which is not shown here. ( And also not represented in the scatter cause i did just randomly assign a +- like in reboost) I will probably benchmark tomorrow, as for that i want to restart my pc to have a clean environment. Question: Where should the python code for generating this plot go? As i guess it is pretty important to have the opportunity to validate this at any time, but also this can not be part of a Pipeline, as it is a visual confirmation. Also the code depends on |
P00664B and V02160A are the two only cylindrical asymmetric detectors. If you made the plots with legend-pygeom-hpges the asymmetric features will not be shown... But if you are plotting simulated steps then I would expect to see some faint deficit at one corner (the "dent" you mentioned).
This is a good question, the thing is essentially tracked in #179. I will try to find some time soon to figure out how to integrate some Python tools. |
@EricMEsch are you sure the option was not set to treat the subtraction solid as a polycone ? |
Pretty sure, Pyg4ometry shows the "dent", the .gdml lists a subtraction solid and Geant4 also shows the subtraction. I used the print(np.sum(np.abs(Dist_G4 - Dist_HPGe) > 1e-6)
> 0
print(np.sum(np.abs(Dist_G4 - Dist_HPGe) > 1e-7)
> 65744112 So the difference is smaller than 1 nm (1e-6 mm). (It might be relevant to note that the original distance in Geant4 was saved in m) Regarding the performance: The ratio of Some more information on that:
|
I guess the effect of the "dent" could be hard to see in that plot, mixed with the rest of the polar angle. Could you try to only select steps close to that region? |
A request from the point of view of coding conventions: remage tries to adopt snake casing ( |
I am not sure ReMaGe is really consistent considering camel case or snake case (e.q. |
Yes you are right, it's not consistent but there is some logic... for example, class members still follow the |
Co-authored-by: Manuel Huber <[email protected]>
so, to summarize, I think there are still two open issued with this:
or is there still anything else? |
Co-authored-by: Manuel Huber <[email protected]>
Maybe not really needed, since we get basically no performance penalty. I think this is good to merge. OK? |
Fixes #154
For some graphical illustration i made a Google Presentation: https://docs.google.com/presentation/d/1gId7s7pBYLD5PBw2EEabf4iIHPTsUEJl24yW60s9TQU/edit#slide=id.p1 (Sorry, in PowerPoint this would look way better)
TLDR:
DistanceToOut()
andDistanceToIn()
functions are used byG4Navigator
itself. This means they should be very reliable (If we start to question the navigation, we start to question the whole simulation). This also means they are computed for every single step, meaning some additional calls in Sensitive Detectors should not slow down the simulation. (I thought about just using thesafety
variable of theG4Navigator
, but it also does additional stuff that we dont want, like ignoring recently exited volumes)DistanceToOut()
andDistanceToIn()
functions are purely virtual inG4VSolid
and are implemented differently for each solid. This means we have to check the implementation of each solid we want to use. I checked the most common:G4Box
it is accurate (I checked the source code and some simple test simulations). Should be accurate for all cartesian solids.G4GenericPolycone
(which are all detectors i think?) it should compute the exact geometrical distance (check the presentation for how) according to the source code. The only exception is if the calculated distance is< 0.5 * kCarTolerance
(which is the safety tolerance of Geant4 to account for floating-point inaccuracies) it returns0
.Although i did not expect the performance to be severely affected, i still did some tests using the
L200.gdml
created with the pygeom-l200 package, registered every single detector and simulated runs of 1e6 10 MeV gammas isotropically in the center of the Strings. This means not always a detector was hit, but in ~40% of the cases at least one was hit.Open Questions:
G4GenericPolycones
by eye and they looked reasonable. But i did not do any quantitative cross-checks.