Events hangs when simulating WLS optical photons

Hello, I am experiencing a weird issue where some of my events completely stop. I am running Geant4 Version v11.0.2.

I am simulating scintillation photons in Liquid Argon (LAr) being WLS by TPB. I have two concentric cylinders of LAr, and the inner one is coated by TPB to WLS the scintillation photons created in it (TPB is a daughter of innerCell).

around the innerCell I have a cylindrical layer of Aluminium which is covered with a skin surface to reflect the incident photons back to the innerCell LAr, and also top/bottom bases made of Aluminium covered with the same skin surface for reflection. I then measure the hit positions of the photons on the bases and sides of the innerCell by looking at the boundary steps of photons from TPB→innerCell and save them to a .csv file.

When running a large amount of events the simulation can sometimes come to a complete stop, even though most events process as intended,and Im not sure why this happens.

I did notice alot of ping-pong steps between the TPB and innerCell / TPB layers themselves which are of 0 length, but not sure if this is related, and I have not been able to solve it by say moving the TPB layers so they are well inside the innerCell instead of sitting exactly on the edges. I know the event stops since Im printing every step taken by every track and the prints just stop (not related to lag).

This is the relevant part of my DetectorConstruction.cc:

// inner cell
innerDiameter = 10.*cm;
innerHeight = 10.*cm;

innerCellSolid = new G4Tubs(“innerCell”,0., innerDiameter/2, innerHeight/2, 0., 360. * deg);

innerCellLogic = new G4LogicalVolume(innerCellSolid, //its solid
fAbsorberMaterial, //its material
“innerCell”); //its name

innerCellPhysi = new G4PVPlacement(0, //no rotation
G4ThreeVector(0,0.,0.),
innerCellLogic, //its logical volume
“innerCell”, //its name
outerCellLogic, //its mother
false, //no boulean operat
0); //copy number

std::cout << “after inner cell” << std::endl;

innerLayerSolid = new G4Tubs(“innerLayer”,innerDiameter/2, innerDiameter/2 + 1.5*mm, innerHeight/2, 0., 360. * deg);

innerLayerLogic = new G4LogicalVolume(innerLayerSolid, //its solid
Al, //its material
“innerLayer”); //its name

innerLayerPhysi = new G4PVPlacement(0,
G4ThreeVector(),
innerLayerLogic, //its logical volume
“innerLayer”, //its name
outerCellLogic, //its mother
false, //no boulean operat
0);

std::cout << “after inner layer” << std::endl;

G4OpticalSurface* OpSurface = new G4OpticalSurface(“name”);
//G4LogicalBorderSurface* Surface = new G4LogicalBorderSurface(“name”,innerCellPhysi,innerLayerPhysi,OpSurface);

OpSurface->SetType(dielectric_metal);
OpSurface->SetModel(unified);
OpSurface->SetFinish(polished);
std::vector pp = {1.5eV, 4.0eV,7.0eV,10.0eV};
//rindex = {1.35, 1.40};
std::vector reflectivity = {0.98, 0.98,0.2,0.1};

G4MaterialPropertiesTable* SMPT = new G4MaterialPropertiesTable();

//SMPT->AddProperty(“RINDEX”, pp, rindex);
SMPT->AddProperty(“REFLECTIVITY”, pp, reflectivity);

OpSurface->SetMaterialPropertiesTable(SMPT);
new G4LogicalSkinSurface(“skinInnerLayer”,innerLayerLogic,OpSurface);

// Top/Bottom optical planes (same radius as inner cell), placed flush
auto planeMat = G4NistManager::Instance()->FindOrBuildMaterial(“G4_Al”); // any bulk; detection is on surface
auto r = innerDiameter/2;
auto t = 1.5*mm;

auto topSolid = new G4Tubs(“TopPlane”, 0, r, t/2, 0, CLHEP::twopi);
auto botSolid = new G4Tubs(“BotPlane”, 0, r, t/2, 0, CLHEP::twopi);
auto topLV = new G4LogicalVolume(topSolid, planeMat, “TopPlaneLV”);
auto botLV = new G4LogicalVolume(botSolid, planeMat, “BotPlaneLV”);

auto topPV = new G4PVPlacement(nullptr, {0, 0, +innerHeight/2 + t/2}, topLV, “TopPlanePV”, outerCellLogic, false, 0);
auto botPV = new G4PVPlacement(nullptr, {0, 0, -innerHeight/2 - t/2}, botLV, “BotPlanePV”, outerCellLogic, false, 0);

new G4LogicalSkinSurface(“skinTop”,topLV,OpSurface);
new G4LogicalSkinSurface(“skinBot”,botLV,OpSurface);

auto mkReflector = [&](const char* name){
auto s = new G4OpticalSurface(name);
s->SetType(dielectric_metal);
s->SetModel(unified);
s->SetFinish(polished);
auto mpt = new G4MaterialPropertiesTable();
// Example: flat 95% reflectivity in visible; add your spectrum
G4double e[2] = {1.5eV, 4.0eV};
G4double R[2] = {0.98, 0.98};
mpt->AddProperty(“REFLECTIVITY”, e, R, 2);
s->SetMaterialPropertiesTable(mpt);
return s;
};
auto reflTop = mkReflector(“ReflTop”);
auto reflBot = mkReflector(“ReflBot”);

// TPB Volumes
const G4double tTPB = 1.5um; // ~1–3 µm film is typical
const G4double inset = 0.1
mm; // instead of 5 um

// mother: LAr logical volume is LArLV (you already have it)

// Side coating: a thin cylindrical shell hugging the wall
auto tpbSideSolid = new G4Tubs(“TPB_Side”, r - tTPB - inset, r - inset, 0.5*innerHeight - tTPB - inset, 0.*deg, 360.*deg);
//auto tpbSideLV = new G4LogicalVolume(tpbSideSolid, tpbMat, “TPB_Side_LV”);
//auto tpbSidePV = new G4PVPlacement(nullptr, G4ThreeVector(), tpbSideLV, “TPB_Side_PV”, innerCellLogic, true, 0);

// Bottom disk
auto tpbBotSolid = new G4Tubs(“TPB_Bot”, 0., r, 0.5*tTPB, 0.deg, 360.deg);
//auto tpbBotLV = new G4LogicalVolume(tpbBotSolid, tpbMat, “TPB_Bot_LV”);
//auto tpbBotPV = new G4PVPlacement(nullptr, G4ThreeVector(0,0,-0.5
innerHeight + 0.5tTPB + inset ), tpbBotLV,“TPB_Bot_PV”, innerCellLogic, true, 0);

// Top disk
auto tpbTopSolid = new G4Tubs(“TPB_Top”, 0., r, 0.5*tTPB, 0.deg, 360.deg);
//auto tpbTopLV = new G4LogicalVolume(tpbTopSolid, tpbMat, “TPB_Top_LV”);
//auto tpbTopPV = new G4PVPlacement(nullptr, G4ThreeVector(0,0, +0.5
innerHeight - 0.5tTPB - inset), tpbTopLV,“TPB_Top_PV”, innerCellLogic, true, 0);

auto tpbUnion1 = new G4UnionSolid(“TPB_union”, tpbSideSolid, tpbTopSolid, nullptr, G4ThreeVector(0,0, +0.5innerHeight - 0.5tTPB - inset));
auto tpbUnion = new G4UnionSolid(“TPB_union2”, tpbUnion1, tpbBotSolid, nullptr, G4ThreeVector(0,0,-0.5innerHeight + 0.5tTPB + inset ));

auto tpbLV = new G4LogicalVolume(tpbUnion, tpbMat, “TPB_LV”);
auto tpbPV = new G4PVPlacement(nullptr, {}, tpbLV, “TPB_PV”, innerCellLogic, true, 0);

Note that I previously did not use unionSolid, I just tried it as a method of solving the ping-pong but this didn’t work.

This is the relevant part of my SteppingAction.cc:

if(particleDef == opticalphoton){    
if(creator && creator->GetProcessName() == "OpWLS" ){

      double t = post->GetGlobalTime()/CLHEP::ns; // Time of flight at boundary

  if (post->GetStepStatus() == fGeomBoundary) {

        const bool fromTPB = (preName.rfind("TPB", 0) == 0);   // any TPB_* PV
        const bool toInner = (postName == "innerCell");
     
        // accept only crossings from tpb to the inner cell
        if (fromTPB && toInner){ 
            //G4cout << "from tpb to inner" << G4endl;

            //fEventAction->numPhotons += 1;
            // classify surface based on which TPB piece we just left (prePV)
            char surfC = 'O';
            const G4String& preName = prePV->GetName();
            if (preName.find("Side") != std::string::npos)     surfC = 'S';
            else if (preName.find("Top") != std::string::npos)      surfC = 'T';
            else if (preName.find("Bot") != std::string::npos) surfC = 'B';
            // else 'O' (other) by default

            const auto p  = post->GetPosition();
            
        if (surfC != 'O') {
              if (t < fEventAction->tZeroEx){
                  fEventAction->tZeroEx = t;
              }
            }

            // Helpers
            auto wrap = [](double a, double w) {
              double r = std::fmod(a, w);
              if (r < 0) r += w;
              return r;
            };
            
            int u_int=0, v_int=0;   // quantized positions
            
            // Bases: (u,v)=(x_cm,z_cm) → mm ticks
            if (surfC=='T' || surfC=='B') {
              u_int = static_cast<int>(std::llround( (p.x()/CLHEP::cm) * kPosScale_cm_to_mm ));
              v_int = static_cast<int>(std::llround( (p.z()/CLHEP::cm) * kPosScale_cm_to_mm ));
            }
            // Side: (u,v)=(phi_rad,y_cm) → tile index & mm ticks
            else if (surfC=='S') {
              //tile count for R=5 cm, tile=0.6 cm
              constexpr double R_cm = 5.0;
              constexpr double tile_cm = 0.6;
              const int nphi = static_cast<int>(std::floor((kTwoPi*R_cm)/tile_cm)); // 52
              const double dphi = kTwoPi / nphi;
            
              double phi = std::atan2(p.z(), p.x());      // [-pi, pi]
              phi = wrap(phi, kTwoPi);                    // [0, 2pi)
              int k = static_cast<int>(std::floor(phi / dphi));
              if (k >= nphi) k = nphi - 1;                // guard
            
              u_int = k;  // store tile index instead of φ (massive savings)
              v_int = static_cast<int>(std::llround( (p.y()/CLHEP::cm) * kPosScale_cm_to_mm ));

              //u_int = static_cast<int>(std::llround( (p.x()/CLHEP::cm) * kPosScale_cm_to_mm ));
              //v_int = static_cast<int>(std::llround( (p.z()/CLHEP::cm) * kPosScale_cm_to_mm ));

            }
            // Time in 10 ps ticks
            int t_10ps = static_cast<int>(std::llround(t * kTimeScale_10ps ));
            

            if (fEventAction->ShouldLogWLS(trackID, surfC, u_int, v_int, t_10ps)) {
                //G4cout << "should log WLS" << G4endl;
                //if (track->GetCurrentStepNumber() > 2500) G4cout << "when logging wls, step number is : " << track->GetCurrentStepNumber() << G4endl;
                fEventAction->BufferHitRow({std::to_string(eventID),std::to_string(trackID),std::string(1,surfC),std::to_string(u_int),std::to_string(v_int),std::to_string(t_10ps)});
            }

  }    
  }
  }

}
}

Any help would be much appreciated, hinting as to what could be causing this, because I’ve been spinning my wheels trying to solve this.

Thanks!


Dear @avivbp

Thank you for your question. The problem may be complex, so to better understand where and when it happens, it may help enabling some verbosity like /tracking/verbose 2 to printout the information of each step of every particle.

Best,

Alvaro

Hi,

This are the prints Im seeing right before the event hangs (for this specific one I caught):

My primary is a 2.5MeV neutron as you can see



G4Track Information: Particle = neutron, Track ID = 1, Parent ID = 0

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -3 m 0 fm 0 fm 2.5 MeV 0 eV 0 fm 0 fm air initStep
1 -23.8 cm 0 fm 0 fm 2.5 MeV 0 eV 2.762 m 2.762 m air Transportation
2 -23.65 cm 0 fm 0 fm 2.5 MeV 0 eV 1.5 mm 2.764 m outerLayerTwo Transportation
3 -22.65 cm 0 fm 0 fm 2.5 MeV 0 eV 1 cm 2.773 m air Transportation
4 -22.5 cm 0 fm 0 fm 2.5 MeV 0 eV 1.5 mm 2.775 m outerLayerOne Transportation
5 -5.15 cm 0 fm 0 fm 2.5 MeV 0 eV 17.35 cm 2.949 m outerCell Transportation
6 -5.061 cm 0 fm 0 fm 2.485 MeV 0 eV 890 um 2.949 m innerLayer hadElastic

:----- List of secondaries ----------------
        Al27:  energy = 15.15 keV  time = 135.1 ns 
:------------------------------------------

7      -5 cm   82.29 um    -249 um   2.485 MeV          0 eV   664.6 um    2.95 m  innerLayer   Transportation
8   -4.99 cm    95.8 um  -289.9 um   2.485 MeV          0 eV   109.1 um    2.95 m   innerCell   Transportation
9   -4.99 cm      96 um  -290.5 um   2.485 MeV          0 eV   1.636 um    2.95 m      TPB_PV   Transportation

10 3.547 cm 1.16 cm -3.51 cm 2.485 MeV 0 eV 9.29 cm 3.043 m innerCell Transportation
11 3.547 cm 1.16 cm -3.51 cm 2.485 MeV 0 eV 1.636 um 3.043 m TPB_PV Transportation
12 3.557 cm 1.161 cm -3.514 cm 2.485 MeV 0 eV 109.1 um 3.043 m innerCell Transportation
13 3.707 cm 1.182 cm -3.575 cm 2.485 MeV 0 eV 1.632 mm 3.045 m innerLayer Transportation
14 20.04 cm 3.382 cm -10.23 cm 2.485 MeV 0 eV 17.77 cm 3.223 m outerCell Transportation
15 20.18 cm 3.401 cm -10.29 cm 0 eV 0 eV 1.498 mm 3.224 m outerLayerOne neutronInelastic

:----- List of secondaries ----------------
     neutron:  energy = 1.518 MeV  time = 147.8 ns 
        Fe56:  energy = 120.1 keV  time = 147.8 ns 
       gamma:  energy = 846.3 keV  time = 147.8 ns 
:------------------------------------------

  • G4Track Information: Particle = gamma, Track ID = 5, Parent ID = 1

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 20.18 cm 3.401 cm -10.29 cm 846.3 keV 0 eV 0 fm 0 fm outerLayerOne initStep
1 20.03 cm 3.104 cm -10.26 cm 846.3 keV 0 eV 3.335 mm 3.335 mm outerLayerOne Transportation
2 8.474 cm -19.83 cm -7.661 cm 516.2 keV 57.97 eV 25.81 cm 26.15 cm outerCell compt

:----- List of secondaries ----------------
          e-:  energy = 329.8 keV  time = 148.6 ns 
          e-:  energy = 35.08 eV   time = 148.6 ns 
          e-:  energy = 220.4 eV   time = 148.6 ns 
:------------------------------------------

3   6.399 cm  -20.23 cm  -7.425 cm   516.2 keV          0 eV   2.125 cm   28.27 cm  outerCell        Rayl
4   3.501 cm  -19.23 cm  -8.171 cm   368.7 keV      57.91 eV   3.156 cm   31.43 cm  outerCell       compt

:----- List of secondaries ----------------
          e-:  energy = 144.3 keV  time = 148.8 ns 
          e-:  energy = 2.681 keV  time = 148.8 ns 
          e-:  energy = 220.4 eV   time = 148.8 ns 
          e-:  energy = 218.2 eV   time = 148.8 ns 
:------------------------------------------

5    2.24 mm  -12.21 cm  -6.745 cm   362.6 keV      29.24 eV   7.871 cm    39.3 cm  outerCell       compt

:----- List of secondaries ----------------
          e-:  energy = 5.914 keV  time = 149.1 ns 
          e-:  energy = 220.2 eV   time = 149.1 ns 
:------------------------------------------

6  -8.471 mm  -9.577 cm  -6.762 cm   151.2 keV      14.62 eV   2.846 cm   42.14 cm  outerCell       compt

:----- List of secondaries ----------------
          e-:  energy = 211.3 keV  time = 149.2 ns 
:------------------------------------------

7  -8.474 mm  -9.818 cm   -6.76 cm   96.92 keV      43.54 eV   2.411 mm   42.39 cm  outerCell       compt

:----- List of secondaries ----------------
          e-:  energy = 54.07 keV  time = 149.2 ns 
          e-:  energy = 205.9 eV   time = 149.2 ns 
:------------------------------------------

8  -1.074 cm  -9.684 cm  -6.655 cm   79.22 keV      29.05 eV    2.84 mm   42.67 cm  outerCell       compt

:----- List of secondaries ----------------
          e-:  energy = 17.44 keV  time = 149.2 ns 
          e-:  energy = 220.4 eV   time = 149.2 ns 
:------------------------------------------

9  -7.752 mm   -10.1 cm  -7.894 cm   79.22 keV          0 eV    1.34 cm   44.01 cm  outerCell        Rayl

10 -8.402 mm -10.46 cm -8.332 cm 0 eV 72.15 eV 5.739 mm 44.58 cm outerCell phot

:----- List of secondaries ----------------
          e-:  energy = 76.05 keV  time = 149.2 ns 
          e-:  energy = 2.617 keV  time = 149.2 ns 
          e-:  energy = 51.91 eV   time = 149.2 ns 
          e-:  energy = 218.2 eV   time = 149.2 ns 
          e-:  energy = 218.2 eV   time = 149.2 ns 
:------------------------------------------

  • G4Track Information: Particle = e-, Track ID = 24, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.402 mm -10.46 cm -8.332 cm 218.2 eV 0 eV 0 fm 0 fm outerCell initStep
1 -8.402 mm -10.46 cm -8.332 cm 0 eV 218.2 eV 13.24 nm 13.24 nm outerCell eIoni
2 -8.402 mm -10.46 cm -8.332 cm 0 eV 0 eV 0 fm 13.24 nm outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 23, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.402 mm -10.46 cm -8.332 cm 218.2 eV 0 eV 0 fm 0 fm outerCell initStep
1 -8.402 mm -10.46 cm -8.332 cm 0 eV 218.2 eV 13.24 nm 13.24 nm outerCell eIoni
2 -8.402 mm -10.46 cm -8.332 cm 0 eV 0 eV 0 fm 13.24 nm outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 22, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.402 mm -10.46 cm -8.332 cm 51.91 eV 0 eV 0 fm 0 fm outerCell initStep
1 -8.402 mm -10.46 cm -8.332 cm 0 eV 51.91 eV 5.798 nm 5.798 nm outerCell eIoni
2 -8.402 mm -10.46 cm -8.332 cm 0 eV 0 eV 0 fm 5.798 nm outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 21, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.402 mm -10.46 cm -8.332 cm 2.617 keV 0 eV 0 fm 0 fm outerCell initStep
1 -8.402 mm -10.46 cm -8.332 cm 0 eV 2.617 keV 307.9 nm 307.9 nm outerCell eIoni
2 -8.402 mm -10.46 cm -8.332 cm 0 eV 0 eV 0 fm 307.9 nm outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 20, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.402 mm -10.46 cm -8.332 cm 76.05 keV 0 eV 0 fm 0 fm outerCell initStep
1 -8.386 mm -10.46 cm -8.331 cm 0 eV 76.05 keV 93.46 um 93.46 um outerCell eIoni
2 -8.386 mm -10.46 cm -8.331 cm 0 eV 0 eV 0 fm 93.46 um outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 19, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -1.074 cm -9.684 cm -6.655 cm 220.4 eV 0 eV 0 fm 0 fm outerCell initStep
1 -1.074 cm -9.684 cm -6.655 cm 0 eV 220.4 eV 13.35 nm 13.35 nm outerCell eIoni
2 -1.074 cm -9.684 cm -6.655 cm 0 eV 0 eV 0 fm 13.35 nm outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 18, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -1.074 cm -9.684 cm -6.655 cm 17.44 keV 0 eV 0 fm 0 fm outerCell initStep
1 -1.074 cm -9.684 cm -6.655 cm 0 eV 17.44 keV 7.332 um 7.332 um outerCell eIoni
2 -1.074 cm -9.684 cm -6.655 cm 0 eV 0 eV 0 fm 7.332 um outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 17, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.474 mm -9.818 cm -6.76 cm 205.9 eV 0 eV 0 fm 0 fm outerCell initStep
1 -8.474 mm -9.818 cm -6.76 cm 0 eV 205.9 eV 12.65 nm 12.65 nm outerCell eIoni
2 -8.474 mm -9.818 cm -6.76 cm 0 eV 0 eV 0 fm 12.65 nm outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 16, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.474 mm -9.818 cm -6.76 cm 54.07 keV 0 eV 0 fm 0 fm outerCell initStep
1 -8.47 mm -9.819 cm -6.761 cm 0 eV 54.07 keV 51.97 um 51.97 um outerCell eIoni
2 -8.47 mm -9.819 cm -6.761 cm 0 eV 0 eV 0 fm 51.97 um outerCell NoProcess


  • G4Track Information: Particle = e-, Track ID = 15, Parent ID = 5

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -8.471 mm -9.577 cm -6.762 cm 211.3 keV 0 eV 0 fm 0 fm outerCell initStep

and then the prints just stop. Hopefully you can learn something from this output