Problem 1885

Summary: G4PhantomParametrisation::GetReplicaNo and G4PSEnergyDeposit3D::GetIndex use different ordering
Product: Geant4 Reporter: Nikolay Yakimov <g.livid>
Component: geometry/navigationAssignee: Pedro.Arce
Status: RESOLVED WONTFIX    
Severity: normal CC: asai
Priority: P4    
Version: 10.2   
Hardware: All   
OS: All   
Attachments: Images

Description Nikolay Yakimov 2016-09-02 01:06:17 CEST
Created attachment 411 [details]
Images

I am using G4PhantomParametrisation with G4PSEnergyDeposit3D sensitive detector to calculate energy deposition distribution from electron scattering in gaseous medium.

When visualising results from G4THitMap, I found that electron beam was shifted from its intended position. What's more, distribution seemed to 'wrap' around World edges.

After a bit of investigation, I found that changing G4PSEnergyDeposit3D::GetIndex() with the following fixes the problem:

    virtual G4int GetIndex(G4Step* aStep) {
      auto point = aStep->GetPreStepPoint();
      return fParam->GetReplicaNo(point->GetPosition(), point->GetMomentumDirection());
    }

Where fParam is G4PhantomParameterisation* used to construct voxelized volume.

From this I would guess that the problem's with G4TouchableHistory::GetReplicaNumber, but I couldn't trace it back further.

To help illustrate the problem (also attached to this message):

Edep distribution with G4PhantomParametrisation::GetReplicaNo:
https://snag.gy/8gRWFB.jpg (G4PhantomParametrisationY.jpg)
https://snag.gy/mwnVI8.jpg (G4PhantomParametrisationZ.jpg)

Edep distribution with G4TouchableHistory::GetReplicaNumber:
https://snag.gy/xi6dtM.jpg (G4TouchableHistoryY.jpg)
https://snag.gy/f6XeHM.jpg (G4TouchableHistoryZ.jpg)
Comment 1 asai 2016-09-02 01:15:34 CEST
Thank you for reporting the issue.
This seems to be an issue of G4PhantomParameterisation class and/or G4RegularNavigator class. This report is to be re-assigned the responsible.
Makoto
Comment 2 Pedro.Arce 2017-09-27 23:55:56 CEST
The problem is the different order in building the index in 

G4PSDoseDeposit3D :  return ix*NY*NZ+iy*NZ+iz;

while in 

G4PhantomParameterisation: return ix+iy*NX+iz*NX*NY

The second one is the order in which the DICOM file its written in the Geant text file, so in my opinion it is the first who should change. Or simply change the order when you construct the G4PSDoseDeposit3D
Comment 3 Pedro.Arce 2017-12-11 11:50:11 CET
The problem is the different order in building the index in

G4PSDoseDeposit3D :  return ix*NY*NZ+iy*NZ+iz;

while in

G4PhantomParameterisation: return ix+iy*NX+iz*NX*NY

The second one is the order in which the DICOM file is written in the Geant4 text file, so you should better change the order when you construct the G4PSDoseDeposit3D
Comment 4 Nikolay Yakimov 2017-12-25 21:06:30 CET
Okay, I'm tired and annoyed and terribly sorry for the language. But what the fuck? How the hell is this "resolved fixed"? I could accept "wontfix", although it would still feel like a "fuck off" to me. But fixed? With a reply boiling down to "fix it yourself"? After 1,5 years of nothing? That feels like a giant "fuck you".

More constructively: Why is the order different? Why do I have to have an intimate knowledge of frankly obscure internal detail to use this? And lastly, why do you assume this is my personal problem? As I said, I've bodged it. I've done what I needed more than a year ago. But I would assume other people are about as likely to step on this god damn landmine as I was. Hint: very. And anyone who runs into this either has to spend hours in a debugger or hours searching the Internet for this very issue. If you don't see the problem, I don't know what to say to you.

Here are a couple ideas on how to actually fix this:
1. Fix G4PSDoseDeposit3D in Geant source tree. I have no idea whether it would have any unintended side effects. Probably will need to fix EVERY G4PS CLASS too.
2. Add a doxygen comment describing the problem and the workaround
3. Fix G4PhantomParametrisation to use the same order as EVERY G4PS CLASS
Comment 5 Gabriele Cosmo 2018-02-06 12:37:08 CET
Hi Nikolay,
I understand your frustration, but also find your tone/language very inappropriate. Sorry.
You're right this issue should have been marked as WONTFIX, and this by any means should be intended as offensive!
The problem, as you may have understood, is not an easy one and this is also the reason why it took so long to seek for a solution and provide an answer to you; we're very sorry for that.
A change to the G4PS* classes would imply a major user interface breakage, affecting the code of the majority of users and applications (with use-cases different from G4PhantomParametrisation) adopting scoring.
We may seek on a way to make a conversion on the fly.. but I'm not sure this is (a) possible, and (b) possible without a cost in performance...
We take on board your critics to have this "anomaly" properly documented and will do so.
Comment 6 Nikolay Yakimov 2018-02-08 19:29:14 CET
As I said, I'm terribly sorry for the language, but I couldn't contain myself. As someone rather invested into FOSS, such handling of what I feel is a legitimate bug report was not just offensive, but also completely antithetical to what I stand for in regards to collaborative software development in general.

> We take on board your critics to have this "anomaly" properly documented and will do so.

Thank you.

As I noted, another option is changing G4PhantomParametrisation, which, as far as I can tell, alone uses Fortran array ordering. I may be wrong though, by no means am I an expert. Besides, backwards compatibility is a concern which I entirely understand.