Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 08:28:30

0001 /**
0002  * Regression test for preserving Geant4 optical photon-stacking settings.
0003  *
0004  * GPU-only transport disables Cerenkov and scintillation secondary stacking so
0005  * Geant4 computes photon counts without paying the CPU tracking cost. This
0006  * test configures both global optical parameters before U4 process creation and
0007  * verifies that `U4Physics::ConstructOp` does not override them.
0008  */
0009 
0010 #include <cstdlib>
0011 #include <iostream>
0012 
0013 #include "G4Box.hh"
0014 #include "G4Cerenkov.hh"
0015 #include "G4LogicalVolume.hh"
0016 #include "G4Material.hh"
0017 #include "G4NistManager.hh"
0018 #include "G4OpticalParameters.hh"
0019 #include "G4PVPlacement.hh"
0020 #include "G4RunManager.hh"
0021 #include "G4Scintillation.hh"
0022 #include "G4SystemOfUnits.hh"
0023 #include "G4ThreeVector.hh"
0024 #include "G4VUserDetectorConstruction.hh"
0025 
0026 #include "OPTICKS_LOG.hh"
0027 #include "U4Physics.hh"
0028 
0029 namespace
0030 {
0031 /**
0032  * Supplies the minimum geometry required for run-manager initialization.
0033  */
0034 class TestDetector final : public G4VUserDetectorConstruction
0035 {
0036   public:
0037     G4VPhysicalVolume* Construct() override
0038     {
0039         G4Material* vacuum =
0040             G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0041         G4Box*           solid = new G4Box("World", 1. * m, 1. * m, 1. * m);
0042         G4LogicalVolume* logical = new G4LogicalVolume(solid, vacuum, "World");
0043         return new G4PVPlacement(
0044             nullptr, G4ThreeVector(), logical, "World", nullptr, false, 0);
0045     }
0046 };
0047 
0048 /**
0049  * Terminates the test executable with a diagnostic when a requirement fails.
0050  *
0051  * @param condition requirement result
0052  * @param message diagnostic printed when `condition` is false
0053  */
0054 void Require(bool condition, const char* message)
0055 {
0056     if (condition)
0057         return;
0058     std::cerr << "U4PhysicsStackingTest FAILED: " << message << std::endl;
0059     std::exit(EXIT_FAILURE);
0060 }
0061 } // namespace
0062 
0063 int main(int argc, char** argv)
0064 {
0065     OPTICKS_LOG(argc, argv);
0066 
0067     G4OpticalParameters* optical = G4OpticalParameters::Instance();
0068     optical->SetDefaults();
0069     optical->SetCerenkovStackPhotons(false);
0070     optical->SetScintStackPhotons(false);
0071 
0072     G4RunManager runManager;
0073     U4Physics*   physics = new U4Physics;
0074     runManager.SetUserInitialization(new TestDetector);
0075     runManager.SetUserInitialization(physics);
0076     runManager.Initialize();
0077 
0078     Require(physics->fCerenkov != nullptr, "Cerenkov process was not created");
0079     Require(physics->fScintillation != nullptr, "scintillation process was not created");
0080     Require(!physics->fCerenkov->GetStackPhotons(),
0081             "Cerenkov stacking setting was overridden");
0082     Require(!physics->fScintillation->GetStackPhotons(),
0083             "scintillation stacking setting was overridden");
0084     return 0;
0085 }