From 8bf373af7cd20229e267fb901b394ccad092af46 Mon Sep 17 00:00:00 2001
From: William Keaton Balunas <bill.balunas@cern.ch>
Date: Mon, 29 Aug 2022 13:46:35 +0200
Subject: [PATCH] JetCalibTools: Fix infinite loop in smearing correction

JetCalibTools: Fix infinite loop in smearing correction
---
 .../Jet/JetCalibTools/Root/JetSmearingCorrection.cxx           | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Reconstruction/Jet/JetCalibTools/Root/JetSmearingCorrection.cxx b/Reconstruction/Jet/JetCalibTools/Root/JetSmearingCorrection.cxx
index 495204cf54c5..165240a86fc3 100644
--- a/Reconstruction/Jet/JetCalibTools/Root/JetSmearingCorrection.cxx
+++ b/Reconstruction/Jet/JetCalibTools/Root/JetSmearingCorrection.cxx
@@ -432,13 +432,14 @@ StatusCode JetSmearingCorrection::calibrate(xAOD::Jet& jet, JetEventInfo&) const
     unsigned long seed = static_cast<unsigned long>(1.e5*fabs(jet.phi()));
     // SetSeed(0) uses the clock, so avoid this
     if(seed == 0) seed = 45583453; // arbitrary number which the seed couldn't otherwise be
+    TRandom3* rng = getTLSRandomGen(seed);
 
     // Get the Gaussian-distributed random number
     // Force this to be a positive value
     // Negative values should be extraordinarily rare, but they do exist
     double smearingFactor = -1;
     while (smearingFactor < 0)
-        smearingFactor = getTLSRandomGen(seed)->Gaus(1.,sigmaSmear);
+        smearingFactor = rng->Gaus(1.,sigmaSmear);
 
     // Apply the smearing factor to the jet as appropriate
     xAOD::JetFourMom_t calibP4 = jet.jetP4();
-- 
GitLab