Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!
From the histograms, the results in (0,-50,0) and (0,0,50) are wrong! Is this one bug of Geant4?
How can I fix it in my codes? Waiting for your help ! Thanks!
This header contains two functions, G4RandomDirection() and G4RandomDirection(G4double cosTheta). First function generates a random unit vector uniformly distributed in a sphere. Second function generates a random unit vector uniformly distributed in a cone.
Points or vectors uniformly distributed on a sphere are not uniform in theta, but in cos(theta). Think of Earth. Real estate runs out towards the poles.
It’s difficult to understand from the code of the detector, how did you place the detector in different positions. When I suggest to check the orientation of the detector, I mean that the detector should be rotated before the move to required position.
I would recommend you to use the constructor for G4PVPlacement with G4Transform3D, instead of the constructor with G4RotationMatrix and G4ThreeVector. The object of the G4Transform3D class can be constructed as a composition of a rotation and then a translation.
I would also recommend you to run your simulation in graphics mode, it will be much easier to detect the source of the problem.
// Position at Z = +50
new G4PVPlacement(G4TranslateZ3D(5.*cm)*G4RotateX3D(0.*deg), ...
// Position at Y = +50
new G4PVPlacement(G4TranslateY3D(5.*cm)*G4RotateX3D(90.*deg), ...
// Position at Z = -50
new G4PVPlacement(G4TranslateZ3D(-5.*cm)*G4RotateX3D(180.*deg), ...
// Position at Y = -50
new G4PVPlacement(G4TranslateY3D(-5.*cm)*G4RotateX3D(270.*deg), ...
In such approach I would expect to see four very similar images.
I have used “new G4PVPlacement(G4TranslateY3D(-5.*cm)*G4RotateX3D(270.*deg), …” to replace my code.
G4Box* det_box
= new G4Box("det_box",5.*cm,5.*cm,0.001*mm);
G4LogicalVolume* det_log= new G4LogicalVolume(det_box,
Vaccum,"det_log",0,0,0);
new G4PVPlacement(G4TranslateY3D(-5.*cm)*G4RotateX3D(270.*deg),det_log,"det_phys", experimentalHall_log, false, 0);///
If this isn’t some oversight in geometry than I suspect your confusion is, as @allison noted, in confusing uniform in theta with cos(theta). The alternative to normalizing would be to evenly sample on a sphere which is not a trivial problem. You would almost certainly want to use libraries such as healpix.
I’ve implemented the setup similar to yours. In the attachment you can find DetectorConstruction.cc (3.3 KB) PrimaryGeneratorAction.cc (3.3 KB)
for the basic example B1, where the detector has been placed at Y=-50. On the image below you can see the trajectories that intersect the detector. As expected, there are two spots with higher density of intersections points.